Skip to content

Commit 02b8c35

Browse files
authored
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 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
1 parent 3c70340 commit 02b8c35

File tree

7 files changed

+54
-1
lines changed

7 files changed

+54
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { bootstrap, isSuccessfulTest } = require('../../utils');
2+
beforeEach(async () => {
3+
await bootstrap({ directory: global.testDirectory, template: __dirname });
4+
});
5+
6+
describe('issue #5176 (flow class properties interaction)', () => {
7+
it('passes tests', async () => {
8+
await isSuccessfulTest({
9+
directory: global.testDirectory,
10+
jestEnvironment: 'node',
11+
});
12+
});
13+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>React App</title>
5+
</head>
6+
<body>
7+
<div id="root"></div>
8+
</body>
9+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class App {
2+
constructor() {
3+
this.foo = this.foo.bind(this);
4+
}
5+
foo: void => void;
6+
foo() {
7+
return 'bar';
8+
}
9+
}
10+
11+
export default App;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import App from './App';
2+
3+
it('creates instance without', () => {
4+
const app = new App();
5+
expect(app.foo()).toBe('bar');
6+
});

fixtures/smoke/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
testEnvironment: 'node',
33
testMatch: ['**/*.test.js'],
4+
testPathIgnorePatterns: ['/src/', 'node_modules'],
45
setupTestFrameworkScriptFile: './setupSmokeTests.js',
56
};

fixtures/utils.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async function bootstrap({ directory, template }) {
1414
);
1515
if (shouldInstallScripts) {
1616
const packageJson = fs.readJsonSync(path.join(directory, 'package.json'));
17-
packageJson.dependencies = Object.assign(packageJson.dependencies, {
17+
packageJson.dependencies = Object.assign({}, packageJson.dependencies, {
1818
'react-scripts': 'latest',
1919
});
2020
fs.writeJsonSync(path.join(directory, 'package.json'), packageJson);
@@ -67,6 +67,17 @@ async function isSuccessfulProduction({ directory }) {
6767
}
6868
}
6969

70+
async function isSuccessfulTest({ directory, jestEnvironment = 'jsdom' }) {
71+
await execa(
72+
'./node_modules/.bin/react-scripts',
73+
['test', '--env', jestEnvironment, '--ci'],
74+
{
75+
cwd: directory,
76+
env: { CI: 'true' },
77+
}
78+
);
79+
}
80+
7081
async function getOutputDevelopment({ directory, env = {} }) {
7182
try {
7283
const { stdout, stderr } = await execa(
@@ -128,6 +139,7 @@ module.exports = {
128139
bootstrap,
129140
isSuccessfulDevelopment,
130141
isSuccessfulProduction,
142+
isSuccessfulTest,
131143
getOutputDevelopment,
132144
getOutputProduction,
133145
};

0 commit comments

Comments
 (0)