forked from compat-table/compat-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhermes.js
148 lines (129 loc) · 4.08 KB
/
hermes.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Node.js test runner for running data-*.js tests with Hermes 'hermes' command.
*
* Reports discrepancies to console; fix them manually in data-*.js files.
* Expects 'hermes' to be already built. Example:
*
* $ node hermes.js --hermes-bin /path/to/hermes --suite suitename
*
* suitename can be 'all'
*/
var fs = require('fs');
var child_process = require('child_process');
var console = require('console');
var runner_support = require('./runner_support');
var argv = require('yargs/yargs')(process.argv.slice(2))
.option('hermes-bin', {
alias: 'b',
type: 'string'
})
.option('suite', {
alias: 's',
type: 'string',
choices: ['all', 'es5', 'es6', 'es2016plus', 'esintl', 'esnext', 'non-standard'],
default: 'all'
})
.option('test-name', {
alias: 't',
type: 'string'
})
// .option('promise', {
// type: 'boolean'
// })
.option('symbol', {
type: 'boolean'
})
.option('proxy', {
type: 'boolean'
})
.option('bail', {
type: 'boolean',
describe: 'Bail of first outdated test'
})
.option('react-native-bundler', {
alias: 'r',
type: 'string'
})
.argv;
var hermesCommand = argv.hermesBin;
var suites = argv.suite;
suites = suites === 'all' ? '' : suites;
var testFamily = argv.reactNativeBundler ? 'React-Native': 'Hermes';
// Key for .res (e.g. test.res.hermes0_7_0), automatic based on `hermes -version`.
var testKey = (function () {
var stdout = child_process.execFileSync(hermesCommand, ['-version'], {
encoding: 'utf-8'
});
var m, prefix;
if (argv.reactNativeBundler) {
prefix = 'reactnative';
// make sure to use hermes bundled with react native release
m = /Hermes release version: for RN\s+(\d+)\.(\d+)(?:\.(\d+))?/.exec(stdout);
} else {
prefix = 'hermes';
m = /Hermes release version:\s+(\d+)\.(\d+)(?:\.(\d+))?/.exec(stdout);
}
if (m) {
return prefix + m[1] + '_' + m[2] + (m[3] ? '_' + m[3] : '');
}
throw new Error('Invalid Hermes version');
})();
console.log('Hermes result key is: test.res.' + testKey);
function getArgs(testFilename) {
var processArgs = [
/*'-enable-eval',*/
/*'-allow-function-to-string',*/
]
.concat([testFilename])
.filter(Boolean);
// if (argv.promise) {
// processArgs.unshift('-Xes6-promise');
// }
if (argv.symbol) {
processArgs.unshift('-Xes6-symbol');
}
if (argv.proxy) {
processArgs.unshift('-Xes6-proxy');
}
// Comment this to see eval warnings
processArgs.unshift('-w');
return processArgs;
}
function testRunner(testFilename) {
var processArgs = getArgs(testFilename);
if (argv.reactNativeBundler) {
var transpilerCommand = 'curl -s --upload-file ./' + testFilename + ' "' + argv.reactNativeBundler + '"';
var traspilerStdout = child_process.execSync(transpilerCommand);
fs.writeFileSync(testFilename, traspilerStdout.toString());
}
try {
var stdout = child_process.execFileSync(hermesCommand, processArgs, {
encoding: 'utf-8'
});
return /^\[SUCCESS\]$/m.test(stdout);
} catch (e) {
// console.log(e);
return false;
}
}
function resultsMatch(expect, actual) {
// Handling notes
if (typeof expect === 'object' && 'val' in expect) {
if (expect.val === 'flagged') {
if (expect.note_id === 'hermes-promise') {
expect = !!argv.promise;
} else if (expect.note_id === 'hermes-symbol') {
expect = !!argv.symbol;
} else if (expect.note_id === 'hermes-proxy') {
expect = !!argv.proxy;
} else {
// expect = true;
expect = expect.val;
}
} else {
expect = expect.val;
}
}
return expect === actual;
}
runner_support.runTests(testRunner, testKey, testFamily, { resultsMatch: resultsMatch, suites: suites, testName: argv.testName, bail: argv.bail });