From 946d1ad4c035581c386b1cc6725e398927636da2 Mon Sep 17 00:00:00 2001 From: Joe Haddad <timer150@gmail.com> Date: Sun, 30 Sep 2018 18:42:37 -0400 Subject: [PATCH 1/9] Test flow types are stripped before class properties are transformed --- .../index.test.js | 13 +++++++++++++ .../package.json | 1 + .../issue-5176-flow-class-properties/src/App.js | 12 ++++++++++++ .../src/App.test.js | 6 ++++++ fixtures/utils.js | 16 ++++++++++++++++ 5 files changed, 48 insertions(+) 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/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 00000000000..72a7a3daf0e --- /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 00000000000..0967ef424bc --- /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/src/App.js b/fixtures/smoke/issue-5176-flow-class-properties/src/App.js new file mode 100644 index 00000000000..25e20018c03 --- /dev/null +++ b/fixtures/smoke/issue-5176-flow-class-properties/src/App.js @@ -0,0 +1,12 @@ +class App { + constructor(props) { + super(props); + 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 00000000000..4991b756f29 --- /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/utils.js b/fixtures/utils.js index 2bcab03c4a2..2f20d78a95a 100644 --- a/fixtures/utils.js +++ b/fixtures/utils.js @@ -67,6 +67,21 @@ async function isSuccessfulProduction({ directory }) { } } +async function isSuccessfulTest({ directory, jestEnvironment = 'jsdom' }) { + const { status, stdout, stderr } = await execa( + './node_modules/.bin/react-scripts', + ['test', '--env', jestEnvironment, '--ci'], + { + cwd: directory, + env: { CI: 'true' }, + } + ); + + if (status !== 0) { + throw new Error(`stdout: ${stdout}${os.EOL + os.EOL}stderr: ${stderr}`); + } +} + async function getOutputDevelopment({ directory, env = {} }) { try { const { stdout, stderr } = await execa( @@ -128,6 +143,7 @@ module.exports = { bootstrap, isSuccessfulDevelopment, isSuccessfulProduction, + isSuccessfulTest, getOutputDevelopment, getOutputProduction, }; From 5b5324da3532b9a68d82880d5209f6217e009e45 Mon Sep 17 00:00:00 2001 From: Joe Haddad <timer150@gmail.com> Date: Sun, 30 Sep 2018 18:51:39 -0400 Subject: [PATCH 2/9] Do not search multiple levels deep --- fixtures/output/jest.config.js | 2 +- fixtures/smoke/jest.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fixtures/output/jest.config.js b/fixtures/output/jest.config.js index fa718fa3ea3..7bb36b64f6e 100644 --- a/fixtures/output/jest.config.js +++ b/fixtures/output/jest.config.js @@ -1,5 +1,5 @@ module.exports = { testEnvironment: 'node', - testMatch: ['**/*.test.js'], + testMatch: ['*/*.test.js'], setupTestFrameworkScriptFile: './setupOutputTests.js', }; diff --git a/fixtures/smoke/jest.config.js b/fixtures/smoke/jest.config.js index 9057ec0ea71..06104fdd0b3 100644 --- a/fixtures/smoke/jest.config.js +++ b/fixtures/smoke/jest.config.js @@ -1,5 +1,5 @@ module.exports = { testEnvironment: 'node', - testMatch: ['**/*.test.js'], + testMatch: ['*/*.test.js'], setupTestFrameworkScriptFile: './setupSmokeTests.js', }; From c3b85ebff5e0829b8647fc496c5c10f2c2d3e774 Mon Sep 17 00:00:00 2001 From: Joe Haddad <timer150@gmail.com> Date: Sun, 30 Sep 2018 18:56:04 -0400 Subject: [PATCH 3/9] Revert "Do not search multiple levels deep" This reverts commit 5b5324da3532b9a68d82880d5209f6217e009e45. --- fixtures/output/jest.config.js | 2 +- fixtures/smoke/jest.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fixtures/output/jest.config.js b/fixtures/output/jest.config.js index 7bb36b64f6e..fa718fa3ea3 100644 --- a/fixtures/output/jest.config.js +++ b/fixtures/output/jest.config.js @@ -1,5 +1,5 @@ module.exports = { testEnvironment: 'node', - testMatch: ['*/*.test.js'], + testMatch: ['**/*.test.js'], setupTestFrameworkScriptFile: './setupOutputTests.js', }; diff --git a/fixtures/smoke/jest.config.js b/fixtures/smoke/jest.config.js index 06104fdd0b3..9057ec0ea71 100644 --- a/fixtures/smoke/jest.config.js +++ b/fixtures/smoke/jest.config.js @@ -1,5 +1,5 @@ module.exports = { testEnvironment: 'node', - testMatch: ['*/*.test.js'], + testMatch: ['**/*.test.js'], setupTestFrameworkScriptFile: './setupSmokeTests.js', }; From 5746167dc1d6fb4bef1a5cd1f39517442a16e0f1 Mon Sep 17 00:00:00 2001 From: Joe Haddad <timer150@gmail.com> Date: Sun, 30 Sep 2018 19:07:09 -0400 Subject: [PATCH 4/9] Add missing file for test script to boot --- .../issue-5176-flow-class-properties/public/index.html | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 fixtures/smoke/issue-5176-flow-class-properties/public/index.html 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 00000000000..86010b24067 --- /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> From 8d6135fef625f866e855b3fb2e45733107139736 Mon Sep 17 00:00:00 2001 From: Joe Haddad <timer150@gmail.com> Date: Sun, 30 Sep 2018 19:10:19 -0400 Subject: [PATCH 5/9] Make sure src and node modules are ignored --- fixtures/smoke/jest.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/fixtures/smoke/jest.config.js b/fixtures/smoke/jest.config.js index 9057ec0ea71..b2f8182ebd9 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', }; From 5480a1fc2ada35c21f6766d266ad085a9c12e570 Mon Sep 17 00:00:00 2001 From: Joe Haddad <timer150@gmail.com> Date: Sun, 30 Sep 2018 19:16:37 -0400 Subject: [PATCH 6/9] Fix error --- fixtures/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fixtures/utils.js b/fixtures/utils.js index 2f20d78a95a..d5bcce9f6ab 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); From d36fe36519668bf3da8eb0c71f67576e6d06b3e6 Mon Sep 17 00:00:00 2001 From: Joe Haddad <timer150@gmail.com> Date: Sun, 30 Sep 2018 19:26:22 -0400 Subject: [PATCH 7/9] derp --- fixtures/smoke/issue-5176-flow-class-properties/src/App.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fixtures/smoke/issue-5176-flow-class-properties/src/App.js b/fixtures/smoke/issue-5176-flow-class-properties/src/App.js index 25e20018c03..c6a68613b58 100644 --- a/fixtures/smoke/issue-5176-flow-class-properties/src/App.js +++ b/fixtures/smoke/issue-5176-flow-class-properties/src/App.js @@ -1,6 +1,5 @@ class App { - constructor(props) { - super(props); + constructor() { this.foo = this.foo.bind(this); } foo: void => void; From df0dd75523c973f55e5b3cb4aff6bb74ffcc60a8 Mon Sep 17 00:00:00 2001 From: Joe Haddad <timer150@gmail.com> Date: Sun, 30 Sep 2018 19:39:13 -0400 Subject: [PATCH 8/9] fix test --- fixtures/utils.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fixtures/utils.js b/fixtures/utils.js index d5bcce9f6ab..738a2dc7706 100644 --- a/fixtures/utils.js +++ b/fixtures/utils.js @@ -68,7 +68,7 @@ async function isSuccessfulProduction({ directory }) { } async function isSuccessfulTest({ directory, jestEnvironment = 'jsdom' }) { - const { status, stdout, stderr } = await execa( + const { status, stdout, stderr, ...rest } = await execa( './node_modules/.bin/react-scripts', ['test', '--env', jestEnvironment, '--ci'], { @@ -78,7 +78,11 @@ async function isSuccessfulTest({ directory, jestEnvironment = 'jsdom' }) { ); if (status !== 0) { - throw new Error(`stdout: ${stdout}${os.EOL + os.EOL}stderr: ${stderr}`); + console.log(rest); + throw new Error( + `status: ${status}${os.EOL + os.EOL}stdout: ${stdout}${os.EOL + + os.EOL}stderr: ${stderr}` + ); } } From 1603351dce6461217f7af695e60e47960a42546d Mon Sep 17 00:00:00 2001 From: Joe Haddad <timer150@gmail.com> Date: Sun, 30 Sep 2018 19:55:57 -0400 Subject: [PATCH 9/9] Drop unneeded check --- fixtures/utils.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/fixtures/utils.js b/fixtures/utils.js index 738a2dc7706..bde092f6e3e 100644 --- a/fixtures/utils.js +++ b/fixtures/utils.js @@ -68,7 +68,7 @@ async function isSuccessfulProduction({ directory }) { } async function isSuccessfulTest({ directory, jestEnvironment = 'jsdom' }) { - const { status, stdout, stderr, ...rest } = await execa( + await execa( './node_modules/.bin/react-scripts', ['test', '--env', jestEnvironment, '--ci'], { @@ -76,14 +76,6 @@ async function isSuccessfulTest({ directory, jestEnvironment = 'jsdom' }) { env: { CI: 'true' }, } ); - - if (status !== 0) { - console.log(rest); - throw new Error( - `status: ${status}${os.EOL + os.EOL}stdout: ${stdout}${os.EOL + - os.EOL}stderr: ${stderr}` - ); - } } async function getOutputDevelopment({ directory, env = {} }) {