@@ -28,6 +28,17 @@ const NODE_8_LEGACY_DEPENDENCIES = [
28
28
] ;
29
29
const NODE_10_LEGACY_DEPENDENCIES = [ '[email protected] ' ] ;
30
30
31
+ type JSONValue = string | number | boolean | null | JSONArray | JSONObject ;
32
+
33
+ type JSONObject = {
34
+ [ key : string ] : JSONValue ;
35
+ } ;
36
+ type JSONArray = Array < JSONValue > ;
37
+
38
+ interface TSConfigJSON extends JSONObject {
39
+ compilerOptions : { lib : string [ ] ; target : string } ;
40
+ }
41
+
31
42
/**
32
43
* Run the given shell command, piping the shell process's `stdin`, `stdout`, and `stderr` to that of the current
33
44
* process. Returns contents of `stdout`.
@@ -52,7 +63,7 @@ function installLegacyDeps(legacyDeps: string[] = []): void {
52
63
* it to a `var` solves this by making it redeclarable.
53
64
*
54
65
*/
55
- function addTransformer ( ) : void {
66
+ function addJestTransformer ( ) : void {
56
67
// Though newer `ts-jest` versions support transformers written in TS, the legacy version does not.
57
68
run ( 'yarn tsc --skipLibCheck jest/transformers/constReplacer.ts' ) ;
58
69
@@ -81,6 +92,33 @@ function addTransformer(): void {
81
92
fs . writeFileSync ( path . resolve ( 'jest/jest.config.js' ) , code ) ;
82
93
}
83
94
95
+ /**
96
+ * Modify a json file on disk.
97
+ *
98
+ * @param filepath The path to the file to be modified
99
+ * @param transformer A function which takes the JSON data as input, mutates it in place, and returns it.
100
+ */
101
+ export function modifyJSONFile ( filepath : string , transformer : ( json : JSONObject ) => JSONObject ) : void {
102
+ const fileContents = fs
103
+ . readFileSync ( filepath )
104
+ . toString ( )
105
+ . replace ( / \/ \/ .* \n / g, '' ) ;
106
+ // fileContents.replace(/\/\/.*\n/g, '');
107
+ const json = JSON . parse ( fileContents ) ;
108
+ const newJSON = transformer ( json ) ;
109
+ fs . writeFileSync ( filepath , JSON . stringify ( newJSON , null , 2 ) ) ;
110
+ }
111
+
112
+ const es6ifyTestTSConfig = ( pkg : string ) : void => {
113
+ const filepath = `packages/${ pkg } /tsconfig.test.json` ;
114
+ const transformer = ( json : JSONObject ) : JSONObject => {
115
+ const tsconfig = json as TSConfigJSON ;
116
+ tsconfig . compilerOptions . target = 'es6' ;
117
+ return json ;
118
+ } ;
119
+ modifyJSONFile ( filepath , transformer ) ;
120
+ } ;
121
+
84
122
/**
85
123
* Skip tests which don't apply to Node and therefore don't need to run in older Node versions.
86
124
*
@@ -107,15 +145,22 @@ function runTests(): void {
107
145
if ( CURRENT_NODE_VERSION === '8' ) {
108
146
installLegacyDeps ( NODE_8_LEGACY_DEPENDENCIES ) ;
109
147
// Inject a `const`-to-`var` transformer, in order to stop Node 8 from complaining when we shadow `global`
110
- addTransformer ( ) ;
148
+ addJestTransformer ( ) ;
111
149
// TODO Right now, this just skips incompatible tests, but it could be skipping more (hence the aspirational name),
112
150
// and not just in Node 8. See `skipNonNodeTests`'s docstring.
113
151
skipNonNodeTests ( ) ;
152
+ es6ifyTestTSConfig ( 'utils' ) ;
114
153
runWithIgnores ( NODE_8_SKIP_TESTS_PACKAGES ) ;
115
154
}
116
155
//
117
156
else if ( CURRENT_NODE_VERSION === '10' ) {
118
157
installLegacyDeps ( NODE_10_LEGACY_DEPENDENCIES ) ;
158
+ es6ifyTestTSConfig ( 'utils' ) ;
159
+ runWithIgnores ( DEFAULT_SKIP_TESTS_PACKAGES ) ;
160
+ }
161
+ //
162
+ else if ( CURRENT_NODE_VERSION === '12' ) {
163
+ es6ifyTestTSConfig ( 'utils' ) ;
119
164
runWithIgnores ( DEFAULT_SKIP_TESTS_PACKAGES ) ;
120
165
}
121
166
//
0 commit comments