Skip to content

Commit

Permalink
Add test fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed May 17, 2021
1 parent d57c1a4 commit 7dfdd14
Show file tree
Hide file tree
Showing 62 changed files with 11,612 additions and 0 deletions.
25 changes: 25 additions & 0 deletions fixtures/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
node_modules

# testing
coverage

# production
build
public/scheduler-unstable_mock.development.js
public/scheduler-unstable_mock.production.min.js
public/react.development.js
public/react.production.min.js
public/react-dom.development.js
public/react-dom.production.min.js
public/react-dom-server.browser.development.js
public/react-dom-server.browser.production.min.js
public/react-dom-test-utils.development.js
public/react-dom-test-utils.production.min.js

# misc
.DS_Store
.env
npm-debug.log
21 changes: 21 additions & 0 deletions fixtures/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Overview

Use nvm to switch node versions.

### Node <15
- Node<15
- Node<15 + jsdom
- Node<15 + jest + jest-environment-node
- Node<15 + jest + jest-environment-node + jsdom
- Node<15 + jest + jest-environment-jsdom + jsdom

### Node >= 15
- Node>=15
- Node>=15 + jsdom
- Node>=15 + jest + jest-environment-node
- Node>=15 + jest + jest-environment-node + jsdom
- Node>=15 + jest + jest-environment-jsdom + jsdom

### Other
- Browser
- React Native
138 changes: 138 additions & 0 deletions fixtures/tests/__tests__/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/** @jest-environment node */


const { spawn, exec } = require('child_process');

const NODE_14_TEST_CASES = [
['node-14'],
["node-14"],
["node-14-jsdom"],
["node-14-jest-env-node"],
["node-14-jest-env-node-jsdom"],
["node-14-jest-env-jsdom"]
]

const NODE_15_TEST_CASES = [
['node-15'],
["node-15"],
["node-15-jsdom"],
["node-15-jest-env-node"],
["node-15-jest-env-node-jsdom"],
["node-15-jest-env-jsdom"]
];

describe.each([['Node <15', NODE_14_TEST_CASES], ['Node 15', NODE_15_TEST_CASES]])('$s', (label, cases) => {
if (process.env.DEBUG) {
console.log('Running', label);
}

it.each(cases)('%s', (command, done) => {
const test = spawn('yarn', [command], {detached: true});
let finished = false;
let timeout;

function debug(...args) {
if (!finished && process.env.DEBUG) {
console.log(command, ...args);
}
}

debug(`testing ${command}...`);

function processResult(reason) {
if (!finished) {
finished = true;
clearTimeout(timeout);
try {
expect(command).toPass(reason);
} finally {
done();
}

}
}

test.stderr.on('data', (data) => {
debug('err', data.toString());
if (data.toString().indexOf('STARTED') >= 0) {
if (!timeout) {
debug('schduling stderr timeout');
timeout = setTimeout(() => {
debug('timed out in stderr, killing');
test.kill('SIGKILL');
processResult('TIMEOUT');
}, 10000);
} else {
debug('timeout already set');
}
}
});
test.stdout.on('data', (data) => {
debug('out', data.toString());
if (data.toString().indexOf('STARTED') >= 0) {
if (!timeout) {
debug('schduling stdout timeout');
timeout = setTimeout(() => {
debug('timed out in out, killing');
process.kill(-test.pid);
processResult('TIMEOUT');
}, 10000);
} else {
debug('timeout already set');
}
}
});
test.on('close', (code) => {
debug('closed', code);

if (code !== 0) {
processResult('FAILED');
} else {
processResult('SUCCESS');
}

});

test.on('error', (err) => {
debug('error', err);
processResult('ERROR');
});

test.on('SIGKILL', () => {
debug('killed');
processResult('KILLED');
});
});
});

expect.extend({
toPass(command, reason) {
const pass = reason === 'SUCCESS';
function getCommand() {
return `(yarn ${command})`
}
if (pass) {
return {
message: () =>
`expected ${command} not to pass`,
pass: true,
};
} else {
return {
message: () => {
switch(reason) {
case 'FAILED':
return `expected ${command} to pass but it failed ${getCommand()}`;
case 'TIMEOUT':
return `expected ${command} to pass but it hung ${getCommand()}`;
case 'ERROR':
return `expected ${command} to pass but it errored ${getCommand()}`;
default:
return `expected ${command} to pass but it failed for an unknown reason ${reason}`;
}
},
pass: false,
};
}
},
});
5 changes: 5 additions & 0 deletions fixtures/tests/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ignore": [],
"presets": ["@babel/preset-env", "@babel/preset-flow", "@babel/preset-react"]

}
39 changes: 39 additions & 0 deletions fixtures/tests/jest/test-jsdom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** @jest-environment jsdom */

console.log('STARTED');

beforeEach(() => {
jest.resetModules();
})

it('should not crash in jsdom env', () => {
require('scheduler');
});

it('should not crash in jsdom env with jest jsdom', () => {
const React = require('react');
const ReactDOM = require('react-dom');
function Effecty() {
React.useEffect(() => {}, []);
return null;
}

ReactDOM.render(<Effecty />, document.createElement('div'));
});

it('should not crash in jsdom env with jsdom', () => {
var { JSDOM } = require('jsdom');
var { window } = new JSDOM();
global.window = window;
global.document = window.document;
global.navigator = {userAgent: ''}
const React = require('react');
const ReactDOM = require('react-dom');

function Effecty() {
React.useEffect(() => {}, []);
return null;
}

ReactDOM.render(<Effecty />, document.createElement('div'));
});
19 changes: 19 additions & 0 deletions fixtures/tests/jest/test-node-jsdom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @jest-environment node */

console.log('STARTED');

it('should not crash in node env with jsdom', () => {
var { JSDOM } = require('jsdom');
var { window } = new JSDOM();
global.window = window;
global.document = window.document;
global.navigator = {userAgent: ''}
const React = require('react');
const ReactDOM = require('react-dom');
function Effecty() {
React.useEffect(() => {}, []);
return null;
}

ReactDOM.render(<Effecty />, document.createElement('div'));
});
9 changes: 9 additions & 0 deletions fixtures/tests/jest/test-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @jest-environment node */

console.log('STARTED');

it('should not crash in node env', () => {
global.window = global;

require('scheduler');
});
8 changes: 8 additions & 0 deletions fixtures/tests/node/test-jsdom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
console.log('STARTED');

var { JSDOM } = require('jsdom');
var { window } = new JSDOM();
global.window = window;
global.document = window.document;

require('scheduler');
6 changes: 6 additions & 0 deletions fixtures/tests/node/test-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
global.__VARIANT__ = true;

console.log('STARTED');

global.window = global; // simulate JSDOM
require('scheduler');
46 changes: 46 additions & 0 deletions fixtures/tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "react-fixtures",
"version": "0.1.0",
"private": true,
"devDependencies": {
"@babel/core": "^7.13.10",
"@babel/plugin-transform-regenerator": "^7.12.13",
"@babel/preset-flow": "^7.12.13",
"@babel/preset-react": "^7.12.13",
"@babel/register": "^7.13.8"
},
"dependencies": {
"jest": "^26.6.3",
"node-14": "npm:node@14",
"node-15": "npm:node@15",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"scheduler": "^0.20.1"
},
"scripts": {
"test-all": "jest all.js",
"node-14": "node_modules/node-14/bin/node node/test-node.js",
"node-14-jsdom": "node_modules/node-14/bin/node node/test-jsdom.js",
"node-14-jest-env-node": "node_modules/node-14/bin/node node_modules/jest-cli/bin/jest.js jest/test-jsdom.js",
"node-14-jest-env-node-jsdom": "node_modules/node-14/bin/node node_modules/jest-cli/bin/jest.js jest/test-node-jsdom.js",
"node-14-jest-env-jsdom": "node_modules/node-14/bin/node node_modules/jest-cli/bin/jest.js jest/test-jsdom.js",
"node-15": "node_modules/node-15/bin/node node/test-node.js",
"node-15-jsdom": "node_modules/node-15/bin/node node/test-jsdom.js",
"node-15-jest-env-node": "node_modules/node-15/bin/node node_modules/jest-cli/bin/jest.js jest/test-jsdom.js",
"node-15-jest-env-node-jsdom": "node_modules/node-15/bin/node node_modules/jest-cli/bin/jest.js jest/test-node-jsdom.js",
"node-15-jest-env-jsdom": "node_modules/node-15/bin/node node_modules/jest-cli/bin/jest.js jest/test-jsdom.js",
"main": "cp -a ./schedulers/main/. node_modules/scheduler",
"pr": "cp -a ./schedulers/pr/. node_modules/scheduler",
"stable": "cp -a ./schedulers/stable/. node_modules/"
},
"jest": {
"testTimeout": 20000,
"testMatch": [
"**/jest/*.js",
"**/__tests__/*.js"
],
"modulePathIgnorePatterns": [
"<rootDir>[/\\\\](schedulers)[/\\\\]"
]
}
}
21 changes: 21 additions & 0 deletions fixtures/tests/schedulers/pr/scheduler/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Facebook, Inc. and its affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions fixtures/tests/schedulers/pr/scheduler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# `scheduler`

This is a package for cooperative scheduling in a browser environment. It is currently used internally by React, but we plan to make it more generic.

The public API for this package is not yet finalized.

### Thanks

The React team thanks [Anton Podviaznikov](https://podviaznikov.com/) for donating the `scheduler` package name.
8 changes: 8 additions & 0 deletions fixtures/tests/schedulers/pr/scheduler/build-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"branch": "17.0.1",
"buildNumber": "222790",
"checksum": "addb3df",
"commit": "8e5adfbd7",
"environment": "ci",
"reactVersion": "17.0.0-8e5adfbd7"
}
Loading

0 comments on commit 7dfdd14

Please sign in to comment.