Skip to content

Commit 7dfdd14

Browse files
committed
Add test fixture
1 parent d57c1a4 commit 7dfdd14

File tree

62 files changed

+11612
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+11612
-0
lines changed

fixtures/tests/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
build
11+
public/scheduler-unstable_mock.development.js
12+
public/scheduler-unstable_mock.production.min.js
13+
public/react.development.js
14+
public/react.production.min.js
15+
public/react-dom.development.js
16+
public/react-dom.production.min.js
17+
public/react-dom-server.browser.development.js
18+
public/react-dom-server.browser.production.min.js
19+
public/react-dom-test-utils.development.js
20+
public/react-dom-test-utils.production.min.js
21+
22+
# misc
23+
.DS_Store
24+
.env
25+
npm-debug.log

fixtures/tests/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Overview
2+
3+
Use nvm to switch node versions.
4+
5+
### Node <15
6+
- Node<15
7+
- Node<15 + jsdom
8+
- Node<15 + jest + jest-environment-node
9+
- Node<15 + jest + jest-environment-node + jsdom
10+
- Node<15 + jest + jest-environment-jsdom + jsdom
11+
12+
### Node >= 15
13+
- Node>=15
14+
- Node>=15 + jsdom
15+
- Node>=15 + jest + jest-environment-node
16+
- Node>=15 + jest + jest-environment-node + jsdom
17+
- Node>=15 + jest + jest-environment-jsdom + jsdom
18+
19+
### Other
20+
- Browser
21+
- React Native

fixtures/tests/__tests__/all.js

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/** @jest-environment node */
2+
3+
4+
const { spawn, exec } = require('child_process');
5+
6+
const NODE_14_TEST_CASES = [
7+
['node-14'],
8+
["node-14"],
9+
["node-14-jsdom"],
10+
["node-14-jest-env-node"],
11+
["node-14-jest-env-node-jsdom"],
12+
["node-14-jest-env-jsdom"]
13+
]
14+
15+
const NODE_15_TEST_CASES = [
16+
['node-15'],
17+
["node-15"],
18+
["node-15-jsdom"],
19+
["node-15-jest-env-node"],
20+
["node-15-jest-env-node-jsdom"],
21+
["node-15-jest-env-jsdom"]
22+
];
23+
24+
describe.each([['Node <15', NODE_14_TEST_CASES], ['Node 15', NODE_15_TEST_CASES]])('$s', (label, cases) => {
25+
if (process.env.DEBUG) {
26+
console.log('Running', label);
27+
}
28+
29+
it.each(cases)('%s', (command, done) => {
30+
const test = spawn('yarn', [command], {detached: true});
31+
let finished = false;
32+
let timeout;
33+
34+
function debug(...args) {
35+
if (!finished && process.env.DEBUG) {
36+
console.log(command, ...args);
37+
}
38+
}
39+
40+
debug(`testing ${command}...`);
41+
42+
function processResult(reason) {
43+
if (!finished) {
44+
finished = true;
45+
clearTimeout(timeout);
46+
try {
47+
expect(command).toPass(reason);
48+
} finally {
49+
done();
50+
}
51+
52+
}
53+
}
54+
55+
test.stderr.on('data', (data) => {
56+
debug('err', data.toString());
57+
if (data.toString().indexOf('STARTED') >= 0) {
58+
if (!timeout) {
59+
debug('schduling stderr timeout');
60+
timeout = setTimeout(() => {
61+
debug('timed out in stderr, killing');
62+
test.kill('SIGKILL');
63+
processResult('TIMEOUT');
64+
}, 10000);
65+
} else {
66+
debug('timeout already set');
67+
}
68+
}
69+
});
70+
test.stdout.on('data', (data) => {
71+
debug('out', data.toString());
72+
if (data.toString().indexOf('STARTED') >= 0) {
73+
if (!timeout) {
74+
debug('schduling stdout timeout');
75+
timeout = setTimeout(() => {
76+
debug('timed out in out, killing');
77+
process.kill(-test.pid);
78+
processResult('TIMEOUT');
79+
}, 10000);
80+
} else {
81+
debug('timeout already set');
82+
}
83+
}
84+
});
85+
test.on('close', (code) => {
86+
debug('closed', code);
87+
88+
if (code !== 0) {
89+
processResult('FAILED');
90+
} else {
91+
processResult('SUCCESS');
92+
}
93+
94+
});
95+
96+
test.on('error', (err) => {
97+
debug('error', err);
98+
processResult('ERROR');
99+
});
100+
101+
test.on('SIGKILL', () => {
102+
debug('killed');
103+
processResult('KILLED');
104+
});
105+
});
106+
});
107+
108+
expect.extend({
109+
toPass(command, reason) {
110+
const pass = reason === 'SUCCESS';
111+
function getCommand() {
112+
return `(yarn ${command})`
113+
}
114+
if (pass) {
115+
return {
116+
message: () =>
117+
`expected ${command} not to pass`,
118+
pass: true,
119+
};
120+
} else {
121+
return {
122+
message: () => {
123+
switch(reason) {
124+
case 'FAILED':
125+
return `expected ${command} to pass but it failed ${getCommand()}`;
126+
case 'TIMEOUT':
127+
return `expected ${command} to pass but it hung ${getCommand()}`;
128+
case 'ERROR':
129+
return `expected ${command} to pass but it errored ${getCommand()}`;
130+
default:
131+
return `expected ${command} to pass but it failed for an unknown reason ${reason}`;
132+
}
133+
},
134+
pass: false,
135+
};
136+
}
137+
},
138+
});

fixtures/tests/babel.config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ignore": [],
3+
"presets": ["@babel/preset-env", "@babel/preset-flow", "@babel/preset-react"]
4+
5+
}

fixtures/tests/jest/test-jsdom.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/** @jest-environment jsdom */
2+
3+
console.log('STARTED');
4+
5+
beforeEach(() => {
6+
jest.resetModules();
7+
})
8+
9+
it('should not crash in jsdom env', () => {
10+
require('scheduler');
11+
});
12+
13+
it('should not crash in jsdom env with jest jsdom', () => {
14+
const React = require('react');
15+
const ReactDOM = require('react-dom');
16+
function Effecty() {
17+
React.useEffect(() => {}, []);
18+
return null;
19+
}
20+
21+
ReactDOM.render(<Effecty />, document.createElement('div'));
22+
});
23+
24+
it('should not crash in jsdom env with jsdom', () => {
25+
var { JSDOM } = require('jsdom');
26+
var { window } = new JSDOM();
27+
global.window = window;
28+
global.document = window.document;
29+
global.navigator = {userAgent: ''}
30+
const React = require('react');
31+
const ReactDOM = require('react-dom');
32+
33+
function Effecty() {
34+
React.useEffect(() => {}, []);
35+
return null;
36+
}
37+
38+
ReactDOM.render(<Effecty />, document.createElement('div'));
39+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** @jest-environment node */
2+
3+
console.log('STARTED');
4+
5+
it('should not crash in node env with jsdom', () => {
6+
var { JSDOM } = require('jsdom');
7+
var { window } = new JSDOM();
8+
global.window = window;
9+
global.document = window.document;
10+
global.navigator = {userAgent: ''}
11+
const React = require('react');
12+
const ReactDOM = require('react-dom');
13+
function Effecty() {
14+
React.useEffect(() => {}, []);
15+
return null;
16+
}
17+
18+
ReactDOM.render(<Effecty />, document.createElement('div'));
19+
});

fixtures/tests/jest/test-node.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @jest-environment node */
2+
3+
console.log('STARTED');
4+
5+
it('should not crash in node env', () => {
6+
global.window = global;
7+
8+
require('scheduler');
9+
});

fixtures/tests/node/test-jsdom.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
console.log('STARTED');
2+
3+
var { JSDOM } = require('jsdom');
4+
var { window } = new JSDOM();
5+
global.window = window;
6+
global.document = window.document;
7+
8+
require('scheduler');

fixtures/tests/node/test-node.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global.__VARIANT__ = true;
2+
3+
console.log('STARTED');
4+
5+
global.window = global; // simulate JSDOM
6+
require('scheduler');

fixtures/tests/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "react-fixtures",
3+
"version": "0.1.0",
4+
"private": true,
5+
"devDependencies": {
6+
"@babel/core": "^7.13.10",
7+
"@babel/plugin-transform-regenerator": "^7.12.13",
8+
"@babel/preset-flow": "^7.12.13",
9+
"@babel/preset-react": "^7.12.13",
10+
"@babel/register": "^7.13.8"
11+
},
12+
"dependencies": {
13+
"jest": "^26.6.3",
14+
"node-14": "npm:node@14",
15+
"node-15": "npm:node@15",
16+
"react": "^17.0.0",
17+
"react-dom": "^17.0.0",
18+
"scheduler": "^0.20.1"
19+
},
20+
"scripts": {
21+
"test-all": "jest all.js",
22+
"node-14": "node_modules/node-14/bin/node node/test-node.js",
23+
"node-14-jsdom": "node_modules/node-14/bin/node node/test-jsdom.js",
24+
"node-14-jest-env-node": "node_modules/node-14/bin/node node_modules/jest-cli/bin/jest.js jest/test-jsdom.js",
25+
"node-14-jest-env-node-jsdom": "node_modules/node-14/bin/node node_modules/jest-cli/bin/jest.js jest/test-node-jsdom.js",
26+
"node-14-jest-env-jsdom": "node_modules/node-14/bin/node node_modules/jest-cli/bin/jest.js jest/test-jsdom.js",
27+
"node-15": "node_modules/node-15/bin/node node/test-node.js",
28+
"node-15-jsdom": "node_modules/node-15/bin/node node/test-jsdom.js",
29+
"node-15-jest-env-node": "node_modules/node-15/bin/node node_modules/jest-cli/bin/jest.js jest/test-jsdom.js",
30+
"node-15-jest-env-node-jsdom": "node_modules/node-15/bin/node node_modules/jest-cli/bin/jest.js jest/test-node-jsdom.js",
31+
"node-15-jest-env-jsdom": "node_modules/node-15/bin/node node_modules/jest-cli/bin/jest.js jest/test-jsdom.js",
32+
"main": "cp -a ./schedulers/main/. node_modules/scheduler",
33+
"pr": "cp -a ./schedulers/pr/. node_modules/scheduler",
34+
"stable": "cp -a ./schedulers/stable/. node_modules/"
35+
},
36+
"jest": {
37+
"testTimeout": 20000,
38+
"testMatch": [
39+
"**/jest/*.js",
40+
"**/__tests__/*.js"
41+
],
42+
"modulePathIgnorePatterns": [
43+
"<rootDir>[/\\\\](schedulers)[/\\\\]"
44+
]
45+
}
46+
}

0 commit comments

Comments
 (0)