Skip to content

Commit

Permalink
Test class properties (#5183)
Browse files Browse the repository at this point in the history
* 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 5b5324d.

* Add missing file for test script to boot

* Make sure src and node modules are ignored

* Fix error

* derp

* fix test

* Drop unneeded check
  • Loading branch information
Timer committed Oct 1, 2018
1 parent 3c70340 commit 02b8c35
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
13 changes: 13 additions & 0 deletions fixtures/smoke/issue-5176-flow-class-properties/index.test.js
Original file line number Diff line number Diff line change
@@ -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',
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>React App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
11 changes: 11 additions & 0 deletions fixtures/smoke/issue-5176-flow-class-properties/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class App {
constructor() {
this.foo = this.foo.bind(this);
}
foo: void => void;
foo() {
return 'bar';
}
}

export default App;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import App from './App';

it('creates instance without', () => {
const app = new App();
expect(app.foo()).toBe('bar');
});
1 change: 1 addition & 0 deletions fixtures/smoke/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
testEnvironment: 'node',
testMatch: ['**/*.test.js'],
testPathIgnorePatterns: ['/src/', 'node_modules'],
setupTestFrameworkScriptFile: './setupSmokeTests.js',
};
14 changes: 13 additions & 1 deletion fixtures/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -128,6 +139,7 @@ module.exports = {
bootstrap,
isSuccessfulDevelopment,
isSuccessfulProduction,
isSuccessfulTest,
getOutputDevelopment,
getOutputProduction,
};

0 comments on commit 02b8c35

Please sign in to comment.