-
Notifications
You must be signed in to change notification settings - Fork 45.5k
/
ReactClassEquivalence-test.js
77 lines (66 loc) · 2.13 KB
/
ReactClassEquivalence-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/
'use strict';
const spawnSync = require('child_process').spawnSync;
describe('ReactClassEquivalence', () => {
it('tests the same thing for es6 classes and CoffeeScript', () => {
const result1 = runJest('ReactCoffeeScriptClass-test.coffee');
const result2 = runJest('ReactES6Class-test.js');
compareResults(result1, result2);
});
it('tests the same thing for es6 classes and TypeScript', () => {
const result1 = runJest('ReactTypeScriptClass-test.ts');
const result2 = runJest('ReactES6Class-test.js');
compareResults(result1, result2);
});
});
function runJest(testFile) {
const cwd = process.cwd();
const extension = process.platform === 'win32' ? '.cmd' : '';
const command = process.env.npm_lifecycle_event;
if (!command.startsWith('test')) {
throw new Error(
'Expected this test to run as a result of one of test commands.',
);
}
const result = spawnSync('yarn' + extension, [command, testFile], {
cwd,
env: Object.assign({}, process.env, {
REACT_CLASS_EQUIVALENCE_TEST: 'true',
// Remove these so that the test file is not filtered out by the mechanism
// we use to parallelize tests in CI
CIRCLE_NODE_TOTAL: '',
CIRCLE_NODE_INDEX: '',
}),
});
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
throw new Error(
'jest process exited with: ' +
result.status +
'\n' +
'stdout: ' +
result.stdout.toString() +
'stderr: ' +
result.stderr.toString(),
);
}
return result.stdout.toString() + result.stderr.toString();
}
function compareResults(a, b) {
const regexp = /EQUIVALENCE.*$/gm;
const aSpecs = (a.match(regexp) || []).sort().join('\n');
const bSpecs = (b.match(regexp) || []).sort().join('\n');
if (aSpecs.length === 0 && bSpecs.length === 0) {
throw new Error('No spec results found in the output');
}
expect(aSpecs).toEqual(bSpecs);
}