Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test class properties #5183

Merged
merged 9 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};