Unverified Commit 02b8c355 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub
Browse files

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 5b5324da.

* Add missing file for test script to boot

* Make sure src and node modules are ignored

* Fix error

* derp

* fix test

* Drop unneeded check
parent 3c703401
Showing with 54 additions and 1 deletion
+54 -1
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',
});
});
});
{}
<!DOCTYPE html>
<html lang="en">
<head>
<title>React App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
class App {
constructor() {
this.foo = this.foo.bind(this);
}
foo: void => void;
foo() {
return 'bar';
}
}
export default App;
import App from './App';
it('creates instance without', () => {
const app = new App();
expect(app.foo()).toBe('bar');
});
module.exports = { module.exports = {
testEnvironment: 'node', testEnvironment: 'node',
testMatch: ['**/*.test.js'], testMatch: ['**/*.test.js'],
testPathIgnorePatterns: ['/src/', 'node_modules'],
setupTestFrameworkScriptFile: './setupSmokeTests.js', setupTestFrameworkScriptFile: './setupSmokeTests.js',
}; };
...@@ -14,7 +14,7 @@ async function bootstrap({ directory, template }) { ...@@ -14,7 +14,7 @@ async function bootstrap({ directory, template }) {
); );
if (shouldInstallScripts) { if (shouldInstallScripts) {
const packageJson = fs.readJsonSync(path.join(directory, 'package.json')); const packageJson = fs.readJsonSync(path.join(directory, 'package.json'));
packageJson.dependencies = Object.assign(packageJson.dependencies, { packageJson.dependencies = Object.assign({}, packageJson.dependencies, {
'react-scripts': 'latest', 'react-scripts': 'latest',
}); });
fs.writeJsonSync(path.join(directory, 'package.json'), packageJson); fs.writeJsonSync(path.join(directory, 'package.json'), packageJson);
...@@ -67,6 +67,17 @@ async function isSuccessfulProduction({ directory }) { ...@@ -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 = {} }) { async function getOutputDevelopment({ directory, env = {} }) {
try { try {
const { stdout, stderr } = await execa( const { stdout, stderr } = await execa(
...@@ -128,6 +139,7 @@ module.exports = { ...@@ -128,6 +139,7 @@ module.exports = {
bootstrap, bootstrap,
isSuccessfulDevelopment, isSuccessfulDevelopment,
isSuccessfulProduction, isSuccessfulProduction,
isSuccessfulTest,
getOutputDevelopment, getOutputDevelopment,
getOutputProduction, getOutputProduction,
}; };
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment