@@ -11,6 +11,9 @@ import {
11
11
validatePackageName ,
12
12
replaceNameInUTF8File ,
13
13
} from '../editTemplate' ;
14
+ import semver from 'semver' ;
15
+
16
+ const skipIfNode20 = semver . major ( process . version ) === 20 ? test . skip : test ;
14
17
15
18
const FIXTURE_DIR = path . resolve (
16
19
__dirname ,
@@ -44,7 +47,7 @@ afterEach(() => {
44
47
fs . removeSync ( testPath ) ;
45
48
} ) ;
46
49
47
- test ( 'should edit template' , async ( ) => {
50
+ skipIfNode20 ( 'should edit template' , async ( ) => {
48
51
jest . spyOn ( process , 'cwd' ) . mockImplementation ( ( ) => testPath ) ;
49
52
50
53
await changePlaceholderInTemplate ( {
@@ -96,7 +99,7 @@ test('should edit template', async () => {
96
99
) . toMatchSnapshot ( ) ;
97
100
} ) ;
98
101
99
- test ( 'should edit template with custom title' , async ( ) => {
102
+ skipIfNode20 ( 'should edit template with custom title' , async ( ) => {
100
103
jest . spyOn ( process , 'cwd' ) . mockImplementation ( ( ) => testPath ) ;
101
104
102
105
await changePlaceholderInTemplate ( {
@@ -140,25 +143,28 @@ describe('changePlaceholderInTemplate', () => {
140
143
jest . resetAllMocks ( ) ;
141
144
} ) ;
142
145
143
- test ( `should produce a lowercased version of "${ PROJECT_NAME } " in package.json "name" field` , async ( ) => {
144
- await changePlaceholderInTemplate ( {
145
- projectName : PROJECT_NAME ,
146
- placeholderName : PLACEHOLDER_NAME ,
147
- } ) ;
148
-
149
- const oldPackageJsonFile = fs . readFileSync (
150
- path . resolve ( FIXTURE_DIR , 'package.json' ) ,
151
- 'utf8' ,
152
- ) ;
153
- const newPackageJsonFile = fs . readFileSync (
154
- path . resolve ( testPath , 'package.json' ) ,
155
- 'utf8' ,
156
- ) ;
157
-
158
- expect (
159
- snapshotDiff ( oldPackageJsonFile , newPackageJsonFile , { contextLines : 1 } ) ,
160
- ) . toMatchSnapshot ( ) ;
161
- } ) ;
146
+ skipIfNode20 (
147
+ `should produce a lowercased version of "${ PROJECT_NAME } " in package.json "name" field` ,
148
+ async ( ) => {
149
+ await changePlaceholderInTemplate ( {
150
+ projectName : PROJECT_NAME ,
151
+ placeholderName : PLACEHOLDER_NAME ,
152
+ } ) ;
153
+
154
+ const oldPackageJsonFile = fs . readFileSync (
155
+ path . resolve ( FIXTURE_DIR , 'package.json' ) ,
156
+ 'utf8' ,
157
+ ) ;
158
+ const newPackageJsonFile = fs . readFileSync (
159
+ path . resolve ( testPath , 'package.json' ) ,
160
+ 'utf8' ,
161
+ ) ;
162
+
163
+ expect (
164
+ snapshotDiff ( oldPackageJsonFile , newPackageJsonFile , { contextLines : 1 } ) ,
165
+ ) . toMatchSnapshot ( ) ;
166
+ } ,
167
+ ) ;
162
168
} ) ;
163
169
164
170
describe ( 'replacePlaceholderWithPackageName' , ( ) => {
@@ -170,22 +176,25 @@ describe('replacePlaceholderWithPackageName', () => {
170
176
jest . resetAllMocks ( ) ;
171
177
} ) ;
172
178
173
- test ( `should replace name in package.json with ${ PACKAGE_NAME } value` , async ( ) => {
174
- await replacePlaceholderWithPackageName ( {
175
- projectName : PROJECT_NAME ,
176
- placeholderName : PLACEHOLDER_NAME ,
177
- placeholderTitle : 'Test' ,
178
- packageName : PACKAGE_NAME ,
179
- } ) ;
180
- const packageJsonFile = fs . readFileSync (
181
- path . resolve ( testPath , 'package.json' ) ,
182
- 'utf8' ,
183
- ) ;
184
-
185
- expect ( JSON . parse ( packageJsonFile ) . name ) . toBe ( PACKAGE_NAME ) ;
186
- } ) ;
179
+ skipIfNode20 (
180
+ `should replace name in package.json with ${ PACKAGE_NAME } value` ,
181
+ async ( ) => {
182
+ await replacePlaceholderWithPackageName ( {
183
+ projectName : PROJECT_NAME ,
184
+ placeholderName : PLACEHOLDER_NAME ,
185
+ placeholderTitle : 'Test' ,
186
+ packageName : PACKAGE_NAME ,
187
+ } ) ;
188
+ const packageJsonFile = fs . readFileSync (
189
+ path . resolve ( testPath , 'package.json' ) ,
190
+ 'utf8' ,
191
+ ) ;
192
+
193
+ expect ( JSON . parse ( packageJsonFile ) . name ) . toBe ( PACKAGE_NAME ) ;
194
+ } ,
195
+ ) ;
187
196
188
- test ( 'should update the bundle ID for iOS' , async ( ) => {
197
+ skipIfNode20 ( 'should update the bundle ID for iOS' , async ( ) => {
189
198
await replacePlaceholderWithPackageName ( {
190
199
projectName : PROJECT_NAME ,
191
200
placeholderName : PLACEHOLDER_NAME ,
@@ -204,45 +213,56 @@ describe('replacePlaceholderWithPackageName', () => {
204
213
) . toBeTruthy ( ) ;
205
214
} ) ;
206
215
207
- test ( `should rename Main component name for Android with ${ PROJECT_NAME } ` , async ( ) => {
208
- await replacePlaceholderWithPackageName ( {
209
- projectName : PROJECT_NAME ,
210
- placeholderName : PLACEHOLDER_NAME ,
211
- placeholderTitle : 'Test' ,
212
- packageName : PACKAGE_NAME ,
213
- } ) ;
214
-
215
- const mainActivityFile = fs . readFileSync (
216
- path . resolve (
217
- testPath ,
218
- 'android' ,
219
- 'com' ,
220
- PACKAGE_NAME ,
221
- 'MainActivity.java' ,
222
- ) ,
223
- 'utf8' ,
224
- ) ;
225
-
226
- expect ( mainActivityFile . includes ( `return "${ PROJECT_NAME } "` ) ) . toBeTruthy ( ) ;
227
- } ) ;
216
+ skipIfNode20 (
217
+ `should rename Main component name for Android with ${ PROJECT_NAME } ` ,
218
+ async ( ) => {
219
+ await replacePlaceholderWithPackageName ( {
220
+ projectName : PROJECT_NAME ,
221
+ placeholderName : PLACEHOLDER_NAME ,
222
+ placeholderTitle : 'Test' ,
223
+ packageName : PACKAGE_NAME ,
224
+ } ) ;
225
+
226
+ const mainActivityFile = fs . readFileSync (
227
+ path . resolve (
228
+ testPath ,
229
+ 'android' ,
230
+ 'com' ,
231
+ PACKAGE_NAME ,
232
+ 'MainActivity.java' ,
233
+ ) ,
234
+ 'utf8' ,
235
+ ) ;
236
+
237
+ expect (
238
+ mainActivityFile . includes ( `return "${ PROJECT_NAME } "` ) ,
239
+ ) . toBeTruthy ( ) ;
240
+ } ,
241
+ ) ;
228
242
} ) ;
229
243
230
244
describe ( 'validatePackageName' , ( ) => {
231
- test ( 'should throw an error when package name contains only one segment' , ( ) => {
232
- expect ( ( ) => validatePackageName ( 'example' ) ) . toThrowError (
233
- 'The package name example is invalid. It should contain at least two segments, e.g. com.app' ,
234
- ) ;
235
- } ) ;
245
+ skipIfNode20 (
246
+ 'should throw an error when package name contains only one segment' ,
247
+ ( ) => {
248
+ expect ( ( ) => validatePackageName ( 'example' ) ) . toThrowError (
249
+ 'The package name example is invalid. It should contain at least two segments, e.g. com.app' ,
250
+ ) ;
251
+ } ,
252
+ ) ;
236
253
237
- test ( 'should throw an error when package name contains special characters other than dots' , ( ) => {
238
- expect ( ( ) => validatePackageName ( 'com.organization.a@pp' ) ) . toThrowError (
239
- 'The com.organization.a@pp package name is not valid. It can contain only alphanumeric characters and dots.' ,
240
- ) ;
241
- } ) ;
254
+ skipIfNode20 (
255
+ 'should throw an error when package name contains special characters other than dots' ,
256
+ ( ) => {
257
+ expect ( ( ) => validatePackageName ( 'com.organization.a@pp' ) ) . toThrowError (
258
+ 'The com.organization.a@pp package name is not valid. It can contain only alphanumeric characters and dots.' ,
259
+ ) ;
260
+ } ,
261
+ ) ;
242
262
} ) ;
243
263
244
264
describe ( 'replaceNameInUTF8File' , ( ) => {
245
- test ( 'should replace string in utf8 file' , async ( ) => {
265
+ skipIfNode20 ( 'should replace string in utf8 file' , async ( ) => {
246
266
const pathToUtf8File = path . join (
247
267
testPath ,
248
268
'ios' ,
@@ -266,7 +286,7 @@ describe('replaceNameInUTF8File', () => {
266
286
expect ( afterReplacement ) . toContain ( textToReplace ) ;
267
287
} ) ;
268
288
269
- test ( 'should not replace string in utf8 file' , async ( ) => {
289
+ skipIfNode20 ( 'should not replace string in utf8 file' , async ( ) => {
270
290
const fsWriteFileSpy = jest . spyOn ( fs , 'writeFile' ) ;
271
291
const pathToUtf8File = path . join (
272
292
testPath ,
0 commit comments