@@ -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,34 @@ 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 and returns a mutated version. It may mutate the
100
+ * JSON data in place, but it isn't required to do so.
101
+ */
102
+ export function modifyJSONFile ( filepath : string , transformer : ( json : JSONObject ) => JSONObject ) : void {
103
+ const fileContents = fs
104
+ . readFileSync ( filepath )
105
+ . toString ( )
106
+ // get rid of comments, which the `jsonc` format allows, but which will crash `JSON.parse`
107
+ . replace ( / \/ \/ .* \n / g, '' ) ;
108
+ const json = JSON . parse ( fileContents ) ;
109
+ const newJSON = transformer ( json ) ;
110
+ fs . writeFileSync ( filepath , JSON . stringify ( newJSON , null , 2 ) ) ;
111
+ }
112
+
113
+ const es6ifyTestTSConfig = ( pkg : string ) : void => {
114
+ const filepath = `packages/${ pkg } /tsconfig.test.json` ;
115
+ const transformer = ( json : JSONObject ) : JSONObject => {
116
+ const tsconfig = json as TSConfigJSON ;
117
+ tsconfig . compilerOptions . target = 'es6' ;
118
+ return json ;
119
+ } ;
120
+ modifyJSONFile ( filepath , transformer ) ;
121
+ } ;
122
+
84
123
/**
85
124
* Skip tests which don't apply to Node and therefore don't need to run in older Node versions.
86
125
*
@@ -107,15 +146,22 @@ function runTests(): void {
107
146
if ( CURRENT_NODE_VERSION === '8' ) {
108
147
installLegacyDeps ( NODE_8_LEGACY_DEPENDENCIES ) ;
109
148
// Inject a `const`-to-`var` transformer, in order to stop Node 8 from complaining when we shadow `global`
110
- addTransformer ( ) ;
149
+ addJestTransformer ( ) ;
111
150
// TODO Right now, this just skips incompatible tests, but it could be skipping more (hence the aspirational name),
112
151
// and not just in Node 8. See `skipNonNodeTests`'s docstring.
113
152
skipNonNodeTests ( ) ;
153
+ es6ifyTestTSConfig ( 'utils' ) ;
114
154
runWithIgnores ( NODE_8_SKIP_TESTS_PACKAGES ) ;
115
155
}
116
156
//
117
157
else if ( CURRENT_NODE_VERSION === '10' ) {
118
158
installLegacyDeps ( NODE_10_LEGACY_DEPENDENCIES ) ;
159
+ es6ifyTestTSConfig ( 'utils' ) ;
160
+ runWithIgnores ( DEFAULT_SKIP_TESTS_PACKAGES ) ;
161
+ }
162
+ //
163
+ else if ( CURRENT_NODE_VERSION === '12' ) {
164
+ es6ifyTestTSConfig ( 'utils' ) ;
119
165
runWithIgnores ( DEFAULT_SKIP_TESTS_PACKAGES ) ;
120
166
}
121
167
//
0 commit comments