From 02b8c35529650c870878edd53ead26fd764fd1b3 Mon Sep 17 00:00:00 2001
From: Joe Haddad <timer150@gmail.com>
Date: Sun, 30 Sep 2018 20:26:11 -0400
Subject: [PATCH] Test class properties (#5183)

* Test flow types are stripped before class properties are transformed

* Do not search multiple levels deep

* Revert "Do not search multiple levels deep"

This reverts commit 5b5324da3532b9a68d82880d5209f6217e009e45.

* Add missing file for test script to boot

* Make sure src and node modules are ignored

* Fix error

* derp

* fix test

* Drop unneeded check
---
 .../issue-5176-flow-class-properties/index.test.js | 13 +++++++++++++
 .../issue-5176-flow-class-properties/package.json  |  1 +
 .../public/index.html                              |  9 +++++++++
 .../issue-5176-flow-class-properties/src/App.js    | 11 +++++++++++
 .../src/App.test.js                                |  6 ++++++
 fixtures/smoke/jest.config.js                      |  1 +
 fixtures/utils.js                                  | 14 +++++++++++++-
 7 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 fixtures/smoke/issue-5176-flow-class-properties/index.test.js
 create mode 100644 fixtures/smoke/issue-5176-flow-class-properties/package.json
 create mode 100644 fixtures/smoke/issue-5176-flow-class-properties/public/index.html
 create mode 100644 fixtures/smoke/issue-5176-flow-class-properties/src/App.js
 create mode 100644 fixtures/smoke/issue-5176-flow-class-properties/src/App.test.js

diff --git a/fixtures/smoke/issue-5176-flow-class-properties/index.test.js b/fixtures/smoke/issue-5176-flow-class-properties/index.test.js
new file mode 100644
index 000000000..72a7a3daf
--- /dev/null
+++ b/fixtures/smoke/issue-5176-flow-class-properties/index.test.js
@@ -0,0 +1,13 @@
+const { bootstrap, isSuccessfulTest } = require('../../utils');
+beforeEach(async () => {
+  await bootstrap({ directory: global.testDirectory, template: __dirname });
+});
+
+describe('issue #5176 (flow class properties interaction)', () => {
+  it('passes tests', async () => {
+    await isSuccessfulTest({
+      directory: global.testDirectory,
+      jestEnvironment: 'node',
+    });
+  });
+});
diff --git a/fixtures/smoke/issue-5176-flow-class-properties/package.json b/fixtures/smoke/issue-5176-flow-class-properties/package.json
new file mode 100644
index 000000000..0967ef424
--- /dev/null
+++ b/fixtures/smoke/issue-5176-flow-class-properties/package.json
@@ -0,0 +1 @@
+{}
diff --git a/fixtures/smoke/issue-5176-flow-class-properties/public/index.html b/fixtures/smoke/issue-5176-flow-class-properties/public/index.html
new file mode 100644
index 000000000..86010b240
--- /dev/null
+++ b/fixtures/smoke/issue-5176-flow-class-properties/public/index.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+  <html lang="en">
+  <head>
+    <title>React App</title>
+  </head>
+  <body>
+    <div id="root"></div>
+  </body>
+</html>
diff --git a/fixtures/smoke/issue-5176-flow-class-properties/src/App.js b/fixtures/smoke/issue-5176-flow-class-properties/src/App.js
new file mode 100644
index 000000000..c6a68613b
--- /dev/null
+++ b/fixtures/smoke/issue-5176-flow-class-properties/src/App.js
@@ -0,0 +1,11 @@
+class App {
+  constructor() {
+    this.foo = this.foo.bind(this);
+  }
+  foo: void => void;
+  foo() {
+    return 'bar';
+  }
+}
+
+export default App;
diff --git a/fixtures/smoke/issue-5176-flow-class-properties/src/App.test.js b/fixtures/smoke/issue-5176-flow-class-properties/src/App.test.js
new file mode 100644
index 000000000..4991b756f
--- /dev/null
+++ b/fixtures/smoke/issue-5176-flow-class-properties/src/App.test.js
@@ -0,0 +1,6 @@
+import App from './App';
+
+it('creates instance without', () => {
+  const app = new App();
+  expect(app.foo()).toBe('bar');
+});
diff --git a/fixtures/smoke/jest.config.js b/fixtures/smoke/jest.config.js
index 9057ec0ea..b2f8182eb 100644
--- a/fixtures/smoke/jest.config.js
+++ b/fixtures/smoke/jest.config.js
@@ -1,5 +1,6 @@
 module.exports = {
   testEnvironment: 'node',
   testMatch: ['**/*.test.js'],
+  testPathIgnorePatterns: ['/src/', 'node_modules'],
   setupTestFrameworkScriptFile: './setupSmokeTests.js',
 };
diff --git a/fixtures/utils.js b/fixtures/utils.js
index 2bcab03c4..bde092f6e 100644
--- a/fixtures/utils.js
+++ b/fixtures/utils.js
@@ -14,7 +14,7 @@ async function bootstrap({ directory, template }) {
   );
   if (shouldInstallScripts) {
     const packageJson = fs.readJsonSync(path.join(directory, 'package.json'));
-    packageJson.dependencies = Object.assign(packageJson.dependencies, {
+    packageJson.dependencies = Object.assign({}, packageJson.dependencies, {
       'react-scripts': 'latest',
     });
     fs.writeJsonSync(path.join(directory, 'package.json'), packageJson);
@@ -67,6 +67,17 @@ async function isSuccessfulProduction({ directory }) {
   }
 }
 
+async function isSuccessfulTest({ directory, jestEnvironment = 'jsdom' }) {
+  await execa(
+    './node_modules/.bin/react-scripts',
+    ['test', '--env', jestEnvironment, '--ci'],
+    {
+      cwd: directory,
+      env: { CI: 'true' },
+    }
+  );
+}
+
 async function getOutputDevelopment({ directory, env = {} }) {
   try {
     const { stdout, stderr } = await execa(
@@ -128,6 +139,7 @@ module.exports = {
   bootstrap,
   isSuccessfulDevelopment,
   isSuccessfulProduction,
+  isSuccessfulTest,
   getOutputDevelopment,
   getOutputProduction,
 };
-- 
GitLab