@neurodevs/meta-node 0.19.11 → 0.19.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,8 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { exec as execSync } from 'child_process';
8
+ import path from 'path';
8
9
  import { promisify } from 'util';
9
- import { callsToChdir, callsToExec, callsToFetch, callsToMkdir, callsToReadFile, callsToWriteFile, fakeChdir, fakeExec, fakeFetch, fakeMkdir, fakePathExists, fakeReadFile, fakeWriteFile, resetCallsToChdir, resetCallsToExec, resetCallsToFetch, resetCallsToMkdir, resetCallsToPathExists, resetCallsToReadFile, resetCallsToWriteFile, setFakeExecResult, setFakeFetchResponse, setFakeReadFileResult, setPathShouldExist, } from '@neurodevs/fake-node-core';
10
+ import { callsToExec, callsToFetch, callsToMkdir, callsToReadFile, callsToWriteFile, fakeExec, fakeFetch, fakeMkdir, fakePathExists, fakeReadFile, fakeWriteFile, resetCallsToExec, resetCallsToFetch, resetCallsToMkdir, resetCallsToPathExists, resetCallsToReadFile, resetCallsToWriteFile, setFakeExecResult, setFakeFetchResponse, setFakeReadFileResult, setPathShouldExist, } from '@neurodevs/fake-node-core';
10
11
  import { test, assert } from '@neurodevs/node-tdd';
11
12
  import GitAutocommit from '../../impl/GitAutocommit.js';
12
13
  import NpmAutopackage from '../../impl/NpmAutopackage.js';
@@ -15,9 +16,68 @@ import AbstractPackageTest from '../AbstractPackageTest.js';
15
16
  const exec = promisify(execSync);
16
17
  export default class NpmAutopackageTest extends AbstractPackageTest {
17
18
  static instance;
19
+ static installDir = this.generateId();
20
+ static description = this.generateId();
21
+ static gitNamespace = this.generateId();
22
+ static npmNamespace = this.generateId();
23
+ static keywords = [this.generateId(), this.generateId()];
24
+ static license = this.generateId();
25
+ static author = this.generateId();
26
+ static githubToken = this.generateId();
27
+ static randomId = this.generateId();
28
+ static packageDir = path.join(this.installDir, this.packageName);
29
+ static packageJsonPath = path.join(this.packageDir, 'package.json');
30
+ static gitignorePath = path.join(this.packageDir, '.gitignore');
31
+ static originalGitignore = this.generateId();
32
+ static updatedGitignore = `${this.originalGitignore}\nbuild/`;
33
+ static tsconfigPath = path.join(this.packageDir, 'tsconfig.json');
34
+ static tasksJsonPath = path.join(this.packageDir, '.vscode', 'tasks.json');
35
+ static testDirPath = path.join(this.packageDir, 'src', '__tests__');
36
+ static abstractTestPath = path.join(this.testDirPath, 'AbstractPackageTest.ts');
37
+ static eslintConfigPath = path.join(this.packageDir, 'eslint.config.js');
38
+ static prettierConfigPath = path.join(this.packageDir, 'prettier.config.js');
39
+ static customLib = this.generateId();
40
+ static customType = this.generateId();
41
+ static customInclude = this.generateId();
42
+ static customOption = this.generateId();
43
+ static setupVscodeCmd = 'spruce setup.vscode --all true';
44
+ static checkGenerateIdVersionCmd = `yarn info @neurodevs/generate-id version --silent`;
45
+ static checkNodeTddVersionCmd = `yarn info @neurodevs/node-tdd version --silent`;
46
+ static checkEslintConfigNdxVersionCmd = `yarn info @neurodevs/eslint-config-ndx version --silent`;
47
+ static checkPrettierConfigNdxVersionCmd = `yarn info @neurodevs/prettier-config-ndx version --silent`;
48
+ static dependencies = {
49
+ [this.generateId()]: this.generateId(),
50
+ [this.generateId()]: this.generateId(),
51
+ };
52
+ static yarnInstallDevDepsCommand = 'yarn add -D @neurodevs/generate-id @neurodevs/node-tdd @neurodevs/eslint-config-ndx @neurodevs/prettier-config-ndx';
53
+ static abstractTestFile = `import AbstractModuleTest from '@neurodevs/node-tdd'
54
+
55
+ export default abstract class AbstractPackageTest extends AbstractModuleTest {
56
+ protected static async beforeEach() {
57
+ await super.beforeEach()
58
+ }
59
+ }
60
+ `;
61
+ static eslintConfigFile = `import esConfigNdx from './src/eslint.config.js'
62
+
63
+ export default esConfigNdx
64
+ `;
65
+ static prettierConfigFile = `import prettierConfigNdx from '@neurodevs/prettier-config-ndx'
66
+
67
+ export default prettierConfigNdx
68
+ `;
69
+ static defaultOptions = {
70
+ installDir: this.installDir,
71
+ name: this.packageName,
72
+ description: this.description,
73
+ gitNamespace: this.gitNamespace,
74
+ npmNamespace: this.npmNamespace,
75
+ keywords: this.keywords,
76
+ license: this.license,
77
+ author: this.author,
78
+ };
18
79
  static async beforeEach() {
19
80
  await super.beforeEach();
20
- this.fakeChdir();
21
81
  this.fakeExec();
22
82
  this.fakeFetch();
23
83
  this.fakeMkdir();
@@ -54,7 +114,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
54
114
  'Content-Type': 'application/json',
55
115
  },
56
116
  body: JSON.stringify({
57
- name: this.name,
117
+ name: this.packageName,
58
118
  private: false,
59
119
  description: this.description,
60
120
  auto_init: true,
@@ -64,33 +124,37 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
64
124
  },
65
125
  }, 'Did not call fetch as expected!');
66
126
  }
67
- static async thenChdirToInstallDir() {
68
- await this.run();
69
- assert.isEqual(callsToChdir[0], this.installDir, 'Did not change to installDir!');
70
- }
71
127
  static async thenGitClone() {
72
128
  await this.run();
73
- assert.isEqual(callsToExec[0]?.command, `git clone https://github.com/${this.gitNamespace}/${this.name}.git`, 'Did not call git clone!');
74
- }
75
- static async thenChdirToPackageDir() {
76
- await this.run();
77
- assert.isEqual(callsToChdir[1], this.packageDir, 'Did not change to packageDir!');
129
+ assert.isEqualDeep(callsToExec[0], {
130
+ command: `git clone https://github.com/${this.gitNamespace}/${this.packageName}.git`,
131
+ options: { cwd: this.installDir },
132
+ }, 'Did not call git clone!');
78
133
  }
79
134
  static async thenGitFetchOrigin() {
80
135
  await this.run();
81
- assert.isEqual(callsToExec[1]?.command, `git fetch origin`, 'Did not call git fetch origin!');
136
+ assert.isEqualDeep(callsToExec[1], { command: `git fetch origin`, options: { cwd: this.packageDir } }, 'Did not call git fetch origin!');
82
137
  }
83
138
  static async thenGitFetchResetHard() {
84
139
  await this.run();
85
- assert.isEqual(callsToExec[2]?.command, `git reset --hard origin/main`, 'Did not call git reset hard!');
140
+ assert.isEqualDeep(callsToExec[2], {
141
+ command: `git reset --hard origin/main`,
142
+ options: { cwd: this.packageDir },
143
+ }, 'Did not call git reset hard!');
86
144
  }
87
145
  static async thenSpruceCreateModule() {
88
146
  await this.run();
89
- assert.isEqual(callsToExec[4]?.command, this.createModuleCmd, 'Did not call "spruce create.module"!');
147
+ assert.isEqualDeep(callsToExec[4], {
148
+ command: this.createModuleCmd,
149
+ options: { cwd: this.packageDir },
150
+ }, 'Did not call "spruce create.module"!');
90
151
  }
91
152
  static async thenCommitCreatePackage() {
92
153
  await this.run();
93
- assert.isEqualDeep(FakeAutocommit.callsToConstructor[0]?.commitMessage, `patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})`, 'Did not commit create package changes!');
154
+ assert.isEqualDeep(FakeAutocommit.callsToConstructor[0], {
155
+ commitMessage: `patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})`,
156
+ cwd: this.packageDir,
157
+ }, 'Did not commit create package changes!');
94
158
  }
95
159
  static async thenReadPackageJson() {
96
160
  await this.run();
@@ -136,31 +200,58 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
136
200
  }
137
201
  static async thenCommitUpdatePackage() {
138
202
  await this.run();
139
- assert.isEqualDeep(FakeAutocommit.callsToConstructor[1]?.commitMessage, `patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})`, 'Did not commit update package changes!');
203
+ assert.isEqualDeep(FakeAutocommit.callsToConstructor[1], {
204
+ commitMessage: `patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})`,
205
+ cwd: this.packageDir,
206
+ }, 'Did not commit update package changes!');
140
207
  }
141
208
  static async thenAddBuildDirToGitignore() {
142
209
  await this.run();
143
210
  assert.isEqualDeep(callsToWriteFile[1], {
144
211
  file: this.gitignorePath,
145
- data: this.buildDirGitignorePattern,
212
+ data: '\nbuild/\n',
146
213
  options: { encoding: 'utf-8', flag: 'a' },
147
214
  }, 'Did not update .gitignore as expected!');
148
215
  }
149
216
  static async thenCommitUpdateGitignore() {
150
217
  await this.run();
151
- assert.isEqualDeep(FakeAutocommit.callsToConstructor[2]?.commitMessage, `patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})`, 'Did not commit .gitignore changes!');
218
+ assert.isEqualDeep(FakeAutocommit.callsToConstructor[2], {
219
+ commitMessage: `patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})`,
220
+ cwd: this.packageDir,
221
+ }, 'Did not commit .gitignore changes!');
222
+ }
223
+ static async thenUpdatesTsconfig() {
224
+ await this.run();
225
+ assert.isEqualDeep(callsToWriteFile[2], {
226
+ file: this.tsconfigPath,
227
+ data: JSON.stringify(this.updatedTsconfig, null, 4) + '\n',
228
+ options: { encoding: 'utf-8', flag: 'a' },
229
+ }, 'Did not update tsconfig as expected!');
230
+ }
231
+ static async thenCommitsUpdateTsconfig() {
232
+ await this.run();
233
+ assert.isEqualDeep(FakeAutocommit.callsToConstructor[3], {
234
+ commitMessage: `patch: update tsconfig (@neurodevs/meta-node: ${this.metaNodeVersion})`,
235
+ cwd: this.packageDir,
236
+ }, 'Did not commit tsconfig changes!');
152
237
  }
153
238
  static async thenSpruceSetupVscode() {
154
239
  await this.run();
155
- assert.isEqual(callsToExec[5]?.command, this.setupVscodeCmd, 'Did not call "spruce setup.vscode"!');
240
+ assert.isEqualDeep(callsToExec[5], {
241
+ command: this.setupVscodeCmd,
242
+ options: { cwd: this.packageDir },
243
+ }, 'Did not call "spruce setup.vscode"!');
156
244
  }
157
245
  static async thenCommitVscodeChanges() {
158
246
  await this.run();
159
- assert.isEqualDeep(FakeAutocommit.callsToConstructor[3]?.commitMessage, `patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})`, 'Did not commit vscode changes!');
247
+ assert.isEqualDeep(FakeAutocommit.callsToConstructor[4], {
248
+ commitMessage: `patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})`,
249
+ cwd: this.packageDir,
250
+ }, 'Did not commit vscode changes!');
160
251
  }
161
252
  static async thenUpdatesVscodeTasksJson() {
162
253
  await this.run();
163
- assert.isEqualDeep(callsToWriteFile[2], {
254
+ assert.isEqualDeep(callsToWriteFile[3], {
164
255
  file: this.tasksJsonPath,
165
256
  data: this.updatedTasksJson,
166
257
  options: { encoding: 'utf-8' },
@@ -168,164 +259,253 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
168
259
  }
169
260
  static async thenCommitsUpdateVscodeTasksJson() {
170
261
  await this.run();
171
- assert.isEqualDeep(FakeAutocommit.callsToConstructor[4]?.commitMessage, `patch: update vscode tasks.json (@neurodevs/meta-node: ${this.metaNodeVersion})`, 'Did not commit updated vscode tasks.json changes!');
262
+ assert.isEqualDeep(FakeAutocommit.callsToConstructor[5], {
263
+ commitMessage: `patch: update vscode tasks.json (@neurodevs/meta-node: ${this.metaNodeVersion})`,
264
+ cwd: this.packageDir,
265
+ }, 'Did not commit updated vscode tasks.json changes!');
172
266
  }
173
267
  static async thenInstallsDefaultDevDependencies() {
268
+ this.setShouldInstallDevDeps();
174
269
  await this.run();
175
- assert.isEqual(callsToExec[8]?.command, this.yarnInstallDevDepsCommand, 'Did not install default devDependencies!');
270
+ assert.isEqualDeep(callsToExec[10], {
271
+ command: this.yarnInstallDevDepsCommand,
272
+ options: { cwd: this.packageDir },
273
+ }, 'Did not install default devDependencies!');
176
274
  }
177
275
  static async thenCommitsInstallDefaultDevDependencies() {
276
+ this.setShouldInstallDevDeps();
178
277
  await this.run();
179
- assert.isEqualDeep(FakeAutocommit.callsToConstructor[5]?.commitMessage, `patch: install default devDependencies (@neurodevs/meta-node: ${this.metaNodeVersion})`, 'Did not commit install devDependencies changes!');
278
+ assert.isEqualDeep(FakeAutocommit.callsToConstructor[6], {
279
+ commitMessage: `patch: install default devDependencies (@neurodevs/meta-node: ${this.metaNodeVersion})`,
280
+ cwd: this.packageDir,
281
+ }, 'Did not commit install devDependencies changes!');
180
282
  }
181
283
  static async thenInstallsTestsDirectory() {
182
284
  await this.run();
183
285
  assert.isEqualDeep(callsToMkdir[0], {
184
- path: 'src/__tests__',
286
+ path: this.testDirPath,
185
287
  options: { recursive: true },
186
288
  }, 'Did not install tests directory!');
187
289
  }
188
290
  static async thenInstallsAbstractPackageTest() {
291
+ this.setShouldInstallDevDeps();
189
292
  await this.run();
190
- assert.isEqualDeep(callsToWriteFile[3], {
191
- file: this.abstractPackageTestPath,
192
- data: this.abstractPackageTestFile,
293
+ assert.isEqualDeep(callsToWriteFile[4], {
294
+ file: this.abstractTestPath,
295
+ data: this.abstractTestFile,
193
296
  options: { encoding: 'utf-8' },
194
297
  }, 'Did not install AbstractPackageTest!');
195
298
  }
196
299
  static async thenCommitsInstallAbstractPackageTest() {
300
+ this.setShouldInstallDevDeps();
301
+ await this.run();
302
+ assert.isEqualDeep(FakeAutocommit.callsToConstructor[7], {
303
+ commitMessage: `patch: install AbstractPackageTest (@neurodevs/meta-node: ${this.metaNodeVersion})`,
304
+ cwd: this.packageDir,
305
+ }, 'Did not commit install AbstractPackageTest changes!');
306
+ }
307
+ static async thenInstallsEslintConfigFile() {
308
+ this.setShouldInstallDevDeps();
309
+ await this.run();
310
+ assert.isEqualDeep(callsToWriteFile[5], {
311
+ file: this.eslintConfigPath,
312
+ data: this.eslintConfigFile,
313
+ options: { encoding: 'utf-8' },
314
+ }, 'Did not install eslint.config.js!');
315
+ }
316
+ static async thenCommitsInstallEslintConfigFile() {
317
+ this.setShouldInstallDevDeps();
197
318
  await this.run();
198
- assert.isEqualDeep(FakeAutocommit.callsToConstructor[6]?.commitMessage, `patch: install AbstractPackageTest (@neurodevs/meta-node: ${this.metaNodeVersion})`, 'Did not commit install AbstractPackageTest changes!');
319
+ assert.isEqualDeep(FakeAutocommit.callsToConstructor[8], {
320
+ commitMessage: `patch: install eslint.config.js (@neurodevs/meta-node: ${this.metaNodeVersion})`,
321
+ cwd: this.packageDir,
322
+ }, 'Did not commit install eslint.config.js changes!');
323
+ }
324
+ static async thenInstallsPrettierConfigFile() {
325
+ this.setShouldInstallDevDeps();
326
+ await this.run();
327
+ assert.isEqualDeep(callsToWriteFile[6], {
328
+ file: this.prettierConfigPath,
329
+ data: this.prettierConfigFile,
330
+ options: { encoding: 'utf-8' },
331
+ }, 'Did not install prettier.config.js!');
332
+ }
333
+ static async thenCommitsInstallPrettierConfigFile() {
334
+ this.setShouldInstallDevDeps();
335
+ await this.run();
336
+ assert.isEqualDeep(FakeAutocommit.callsToConstructor[9], {
337
+ commitMessage: `patch: install prettier.config.js (@neurodevs/meta-node: ${this.metaNodeVersion})`,
338
+ cwd: this.packageDir,
339
+ }, 'Did not commit install prettier.config.js changes!');
199
340
  }
200
341
  static async lastlyOpensVscodeAtEnd() {
201
342
  await this.run();
202
- assert.isEqual(callsToExec[9]?.command, 'code .', 'Did not open vscode at end!');
343
+ assert.isEqualDeep(callsToExec[10], { command: 'code .', options: { cwd: this.packageDir } }, 'Did not open vscode at end!');
203
344
  }
204
- static async doesNotCreateRepoInGithubOrgIfDone() {
205
- const fakeResponse = new Response(null, {
206
- status: 200,
207
- statusText: 'OK',
345
+ static async installsDevDependenciesIfGenerateIdNotLatest() {
346
+ setFakeExecResult(this.checkGenerateIdVersionCmd, {
347
+ stdout: '0.0.1',
208
348
  });
209
- setFakeFetchResponse(this.reposUrl, fakeResponse);
210
- await this.createAndRunAutopackage();
349
+ await this.runTwice();
350
+ const calls = callsToExec.filter((call) => call?.command === this.yarnInstallDevDepsCommand);
351
+ assert.isEqualDeep(calls[0], {
352
+ command: this.yarnInstallDevDepsCommand,
353
+ options: { cwd: this.packageDir },
354
+ }, 'Should install default devDependencies if not already installed!');
355
+ }
356
+ static async installsDevDependenciesIfNodeTddNotLatest() {
357
+ this.setShouldInstallDevDeps();
358
+ await this.runTwice();
359
+ const calls = callsToExec.filter((call) => call?.command === this.yarnInstallDevDepsCommand);
360
+ assert.isEqualDeep(calls[0], {
361
+ command: this.yarnInstallDevDepsCommand,
362
+ options: { cwd: this.packageDir },
363
+ }, 'Should install default devDependencies if not already installed!');
364
+ }
365
+ static async installsDevDependenciesIfEslintConfigNdxNotLatest() {
366
+ this.setShouldInstallDevDeps();
367
+ await this.runTwice();
368
+ const calls = callsToExec.filter((call) => call?.command === this.yarnInstallDevDepsCommand);
369
+ assert.isEqualDeep(calls[0], {
370
+ command: this.yarnInstallDevDepsCommand,
371
+ options: { cwd: this.packageDir },
372
+ }, 'Should install default devDependencies if not already installed!');
373
+ }
374
+ static async installsDevDependenciesIfPrettierConfigNdxNotLatest() {
375
+ this.setShouldInstallDevDeps();
376
+ await this.runTwice();
377
+ const calls = callsToExec.filter((call) => call?.command === this.yarnInstallDevDepsCommand);
378
+ assert.isEqualDeep(calls[0], {
379
+ command: this.yarnInstallDevDepsCommand,
380
+ options: { cwd: this.packageDir },
381
+ }, 'Should install default devDependencies if not already installed!');
382
+ }
383
+ static async makeNpmNamespaceOptional() {
384
+ resetCallsToWriteFile();
385
+ const instance = this.NpmAutopackage({
386
+ npmNamespace: undefined,
387
+ });
388
+ await instance.run();
389
+ assert.doesInclude(callsToWriteFile[0]?.data, `"name": "${this.packageName}"`, 'Did not handle missing npmNamespace!');
390
+ }
391
+ static async doesNotCreateRepoInGithubOrgIfDone() {
392
+ await this.runTwice();
211
393
  const numCalls = callsToFetch.filter((call) => call.input === this.orgsUrl).length;
212
- assert.isEqual(numCalls, 0, 'Should not have created repo!');
394
+ assert.isEqual(numCalls, 1, 'Should have created repo once!');
213
395
  }
214
396
  static async doesNotCloneRepoIfDone() {
215
- await this.createAndRunAutopackage();
397
+ await this.runTwice();
216
398
  assert.isEqual(callsToExec.filter((call) => call?.command ===
217
- `git clone https://github.com/${this.gitNamespace}/${this.name}.git`).length, 1, 'Did not clone repo once!');
399
+ `git clone https://github.com/${this.gitNamespace}/${this.packageName}.git`).length, 1, 'Did not clone repo once!');
218
400
  }
219
401
  static async doesNotSpruceCreateModuleIfDone() {
220
- await this.createAndRunAutopackage();
402
+ await this.runTwice();
221
403
  assert.isEqual(callsToExec.filter((call) => call?.command === this.createModuleCmd)
222
404
  .length, 1, 'Did not call spruce create.module once!');
223
405
  }
224
406
  static async doesNotRunSetupVscodeIfDone() {
225
- await this.createAndRunAutopackage();
407
+ await this.runTwice();
226
408
  assert.isEqual(callsToExec.filter((call) => call?.command === this.setupVscodeCmd)
227
409
  .length, 1, 'Did not call spruce setup.vscode once!');
228
410
  }
229
411
  static async doesNotCommitCreatePackageIfDone() {
230
- await this.createAndRunAutopackage();
412
+ await this.runTwice();
231
413
  assert.isEqual(FakeAutocommit.callsToConstructor.filter((call) => call?.commitMessage ===
232
414
  `patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})`).length, 1, 'Did not commit create package changes once!');
233
415
  }
234
416
  static async doesNotCommitUpdatePackageIfDone() {
235
- await this.createAndRunAutopackage();
417
+ await this.runTwice();
236
418
  assert.isEqual(FakeAutocommit.callsToConstructor.filter((call) => call?.commitMessage ===
237
419
  `patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})`).length, 1, 'Did not commit update package changes once!');
238
420
  }
239
421
  static async doesNotCommitUpdateGitignoreIfDone() {
240
- await this.createAndRunAutopackage();
422
+ await this.runTwice();
241
423
  assert.isEqual(FakeAutocommit.callsToConstructor.filter((call) => call?.commitMessage ===
242
424
  `patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})`).length, 1, 'Did not commit gitignore changes once!');
243
425
  }
426
+ static async doesNotCommitUpdateTsconfigIfDone() {
427
+ await this.runTwice();
428
+ assert.isEqual(FakeAutocommit.callsToConstructor.filter((call) => call?.commitMessage ===
429
+ `patch: update tsconfig (@neurodevs/meta-node: ${this.metaNodeVersion})`).length, 1, 'Did not commit tsconfig changes once!');
430
+ }
244
431
  static async doesNotCommitSetupVscodeIfDone() {
245
- await this.createAndRunAutopackage();
432
+ await this.runTwice();
246
433
  assert.isEqual(FakeAutocommit.callsToConstructor.filter((call) => call?.commitMessage ===
247
434
  `patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})`).length, 1, 'Did not commit vscode changes once!');
248
435
  }
249
436
  static async doesNotOverrideOriginalDependencies() {
250
- await this.createAndRunAutopackage();
437
+ await this.runTwice();
251
438
  assert.isEqualDeep(JSON.parse(callsToWriteFile[0]?.data).dependencies, this.dependencies, 'Did not update package.json as expected!');
252
439
  }
253
440
  static async doesNotUpdateTasksJsonIfAlreadyDone() {
254
- setFakeReadFileResult(this.tasksJsonPath, this.updatedTasksJson);
255
- await this.createAndRunAutopackage();
441
+ await this.runTwice();
256
442
  assert.isEqualDeep(callsToWriteFile.filter((call) => call.file === this.tasksJsonPath)
257
- .length, 0, 'Did not update tasks.json once!');
443
+ .length, 1, 'Did not update tasks.json once!');
258
444
  }
259
445
  static async doesNotOpenVscodeIfNotCloned() {
260
- setPathShouldExist(this.name, true);
261
- await this.createAndRunAutopackage();
446
+ setPathShouldExist(this.packageDir, true);
447
+ await this.run();
262
448
  assert.isFalse(callsToExec.some((call) => call?.command === 'code .'), 'Should not open vscode if not cloned!');
263
449
  }
264
- static async installsDevDependenciesIfGenerateIdNotLatest() {
265
- setFakeExecResult(this.checkGenerateIdVersionCmd, {
266
- stdout: '0.0.1',
267
- });
268
- await this.createAndRunAutopackage();
269
- const calls = callsToExec.filter((call) => call?.command === this.yarnInstallDevDepsCommand);
270
- assert.isEqual(calls.length, 1, 'Should not install default devDependencies if already installed!');
271
- }
272
- static async installsDevDependenciesIfNodeTddNotLatest() {
273
- setFakeExecResult(this.checkGenerateIdVersionCmd, {
274
- stdout: '1.0.0',
275
- });
276
- setFakeExecResult(this.checkNodeTddVersionCmd, {
277
- stdout: '0.0.1',
278
- });
279
- await this.createAndRunAutopackage();
280
- const calls = callsToExec.filter((call) => call?.command === this.yarnInstallDevDepsCommand);
281
- assert.isEqual(calls.length, 1, 'Should not install default devDependencies if already installed!');
282
- }
283
450
  static async doesNotThrowIfGenerateIdNotInPackageJson() {
284
451
  setFakeReadFileResult(this.packageJsonPath, this.originalPackageJson.replace('@neurodevs/generate-id', ''));
285
- await this.createAndRunAutopackage();
452
+ await this.runTwice();
286
453
  }
287
454
  static async doesNotInstallAbstractPackageTestIfTsExists() {
288
- setPathShouldExist(this.abstractPackageTestPath, true);
289
- await this.createAndRunAutopackage();
290
- const calls = callsToWriteFile.filter((call) => call.file === this.abstractPackageTestPath);
455
+ setPathShouldExist(this.abstractTestPath, true);
456
+ await this.run();
457
+ const calls = callsToWriteFile.filter((call) => call.file === this.abstractTestPath);
291
458
  assert.isEqual(calls.length, 0, 'Should not install AbstractPackageTest.ts if already exists!');
292
459
  }
293
460
  static async doesNotInstallAbstractPackageTestIfTsxExists() {
294
- setPathShouldExist(`${this.abstractPackageTestPath}x`, true);
295
- await this.createAndRunAutopackage();
296
- const calls = callsToWriteFile.filter((call) => call.file === this.abstractPackageTestPath);
461
+ setPathShouldExist(`${this.abstractTestPath}x`, true);
462
+ await this.run();
463
+ const calls = callsToWriteFile.filter((call) => call.file === this.abstractTestPath);
297
464
  assert.isEqual(calls.length, 0, 'Should not install AbstractPackageTest.tsx if already exists!');
298
465
  }
299
- static async makeNpmNamespaceOptional() {
300
- resetCallsToWriteFile();
301
- const instance = this.NpmAutopackage({
302
- npmNamespace: undefined,
303
- });
304
- await instance.run();
305
- assert.doesInclude(callsToWriteFile[0]?.data, `"name": "${this.name}"`, 'Did not handle missing npmNamespace!');
466
+ static async doesNotInstallEslintConfigFileIfExists() {
467
+ setPathShouldExist(this.eslintConfigPath, true);
468
+ await this.run();
469
+ const calls = callsToWriteFile.filter((call) => call.file === this.eslintConfigPath);
470
+ assert.isEqual(calls.length, 0, 'Should not install eslint.config.js if already exists!');
471
+ }
472
+ static async doesNotInstallPrettierConfigFileIfExists() {
473
+ setPathShouldExist(this.prettierConfigPath, true);
474
+ await this.run();
475
+ const calls = callsToWriteFile.filter((call) => call.file === this.prettierConfigPath);
476
+ assert.isEqual(calls.length, 0, 'Should not install prettier.config.js if already exists!');
306
477
  }
307
478
  static async run() {
308
479
  await this.instance.run();
309
480
  }
310
- static async createAndRunAutopackage() {
311
- const instance = this.NpmAutopackage();
312
- await instance.run();
481
+ static async runTwice() {
482
+ await this.run();
483
+ setPathShouldExist(this.packageDir, true);
484
+ setPathShouldExist(this.packageJsonPath, true);
485
+ setPathShouldExist(this.abstractTestPath, true);
486
+ setPathShouldExist(this.tasksJsonPath, true);
487
+ setFakeReadFileResult(this.packageJsonPath, this.updatedPackageJson);
488
+ setFakeReadFileResult(this.gitignorePath, this.updatedGitignore);
489
+ setFakeReadFileResult(this.tasksJsonPath, this.updatedTasksJson);
490
+ setFakeReadFileResult(this.tsconfigPath, JSON.stringify(this.updatedTsconfig));
491
+ const fakeResponse = new Response(null, {
492
+ status: 200,
493
+ statusText: 'OK',
494
+ });
495
+ setFakeFetchResponse(this.reposUrl, fakeResponse);
496
+ await this.run();
313
497
  }
314
- static get scopedPackageName() {
315
- return `@${this.npmNamespace}/${this.name}`;
498
+ static setShouldInstallDevDeps() {
499
+ setFakeExecResult(this.checkGenerateIdVersionCmd, {
500
+ stdout: '0.0.1',
501
+ });
316
502
  }
317
- static get packageDir() {
318
- return this.name;
503
+ static get scopedPackageName() {
504
+ return `@${this.npmNamespace}/${this.packageName}`;
319
505
  }
320
- static packageJsonPath = 'package.json';
321
- static gitignorePath = '.gitignore';
322
- static buildDirGitignorePattern = '\nbuild/\n';
323
506
  static get createModuleCmd() {
324
- return `spruce create.module --name "${this.name}" --destination "." --description "${this.description}"`;
507
+ return `spruce create.module --name "${this.packageName}" --destination "." --description "${this.description}"`;
325
508
  }
326
- static setupVscodeCmd = 'spruce setup.vscode --all true';
327
- static checkGenerateIdVersionCmd = `yarn info @neurodevs/generate-id version --silent`;
328
- static checkNodeTddVersionCmd = `yarn info @neurodevs/node-tdd version --silent`;
329
509
  static orderJsonKeys(json, keyOrder) {
330
510
  const ordered = {};
331
511
  for (const key of keyOrder) {
@@ -341,14 +521,22 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
341
521
  }
342
522
  return ordered;
343
523
  }
344
- static fakeChdir() {
345
- NpmAutopackage.chdir = fakeChdir;
346
- resetCallsToChdir();
347
- }
348
524
  static fakeExec() {
349
525
  NpmAutopackage.exec = fakeExec;
350
526
  resetCallsToExec();
351
527
  this.setFakeMetaNodeVersion();
528
+ setFakeExecResult(this.checkGenerateIdVersionCmd, {
529
+ stdout: '1.0.0',
530
+ });
531
+ setFakeExecResult(this.checkNodeTddVersionCmd, {
532
+ stdout: '1.0.0',
533
+ });
534
+ setFakeExecResult(this.checkEslintConfigNdxVersionCmd, {
535
+ stdout: '1.0.0',
536
+ });
537
+ setFakeExecResult(this.checkPrettierConfigNdxVersionCmd, {
538
+ stdout: '1.0.0',
539
+ });
352
540
  }
353
541
  static fakeFetch() {
354
542
  NpmAutopackage.fetch = fakeFetch;
@@ -361,13 +549,18 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
361
549
  static fakePathExists() {
362
550
  NpmAutopackage.pathExists = fakePathExists;
363
551
  resetCallsToPathExists();
364
- setPathShouldExist(this.abstractPackageTestPath, false);
552
+ setPathShouldExist(this.packageDir, false);
553
+ setPathShouldExist(this.packageJsonPath, false);
554
+ setPathShouldExist(this.tasksJsonPath, false);
555
+ setPathShouldExist(this.abstractTestPath, false);
365
556
  }
366
557
  static fakeReadFile() {
367
558
  NpmAutopackage.readFile = fakeReadFile;
368
559
  resetCallsToReadFile();
369
560
  setFakeReadFileResult(this.packageJsonPath, this.originalPackageJson);
370
561
  setFakeReadFileResult(this.tasksJsonPath, JSON.stringify(this.originalTasksJson));
562
+ setFakeReadFileResult(this.tsconfigPath, JSON.stringify(this.originalTsconfig));
563
+ setFakeReadFileResult(this.gitignorePath, this.originalGitignore);
371
564
  }
372
565
  static fakeWriteFile() {
373
566
  NpmAutopackage.writeFile = fakeWriteFile;
@@ -384,34 +577,22 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
384
577
  });
385
578
  setFakeFetchResponse(this.reposUrl, fakeResponse);
386
579
  }
387
- static installDir = this.generateId();
388
- static name = this.generateId();
389
- static description = this.generateId();
390
- static gitNamespace = this.generateId();
391
- static npmNamespace = this.generateId();
392
- static keywords = [this.generateId(), this.generateId()];
393
- static license = this.generateId();
394
- static author = this.generateId();
395
- static githubToken = this.generateId();
396
- static randomId = this.generateId();
397
580
  static get reposUrl() {
398
- return `https://api.github.com/repos/${this.gitNamespace}/${this.name}`;
581
+ return `https://api.github.com/repos/${this.gitNamespace}/${this.packageName}`;
399
582
  }
400
583
  static get orgsUrl() {
401
584
  return `https://api.github.com/orgs/${this.gitNamespace}/repos`;
402
585
  }
403
- static dependencies = {
404
- [this.generateId()]: this.generateId(),
405
- [this.generateId()]: this.generateId(),
406
- };
407
586
  static get originalPackageJson() {
408
587
  return JSON.stringify({
409
- name: this.name,
588
+ name: this.packageName,
410
589
  description: 'Old description',
411
590
  dependencies: this.dependencies,
412
591
  devDependencies: {
413
592
  '@neurodevs/generate-id': '^1.0.0',
414
593
  '@neurodevs/node-tdd': '^1.0.0',
594
+ '@neurodevs/eslint-config-ndx': '^1.0.0',
595
+ '@neurodevs/prettier-config-ndx': '^1.0.0',
415
596
  },
416
597
  });
417
598
  }
@@ -420,22 +601,60 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
420
601
  ...JSON.parse(this.originalPackageJson),
421
602
  name: this.scopedPackageName,
422
603
  description: this.description,
604
+ type: 'module',
423
605
  keywords: this.keywords,
424
606
  license: this.license,
425
607
  author: this.author,
426
608
  main: 'build/index.js',
427
- homepage: `https://github.com/${this.gitNamespace}/${this.name}`,
609
+ homepage: `https://github.com/${this.gitNamespace}/${this.packageName}`,
428
610
  repository: {
429
611
  type: 'git',
430
- url: `git+https://github.com/${this.gitNamespace}/${this.name}.git`,
612
+ url: `git+https://github.com/${this.gitNamespace}/${this.packageName}.git`,
431
613
  },
432
614
  bugs: {
433
- url: `https://github.com/${this.gitNamespace}/${this.name}/issues`,
615
+ url: `https://github.com/${this.gitNamespace}/${this.packageName}/issues`,
434
616
  },
435
617
  dependencies: this.dependencies,
436
618
  });
437
619
  }
438
- static tasksJsonPath = '.vscode/tasks.json';
620
+ static get originalTsconfig() {
621
+ return {
622
+ compilerOptions: {
623
+ lib: [this.customLib],
624
+ types: [this.customType],
625
+ },
626
+ include: [this.customInclude],
627
+ customOption: this.customOption,
628
+ };
629
+ }
630
+ static get updatedTsconfig() {
631
+ return {
632
+ ...this.originalTsconfig,
633
+ compilerOptions: {
634
+ module: 'nodenext',
635
+ moduleResolution: 'nodenext',
636
+ target: 'ES2022',
637
+ lib: [this.customLib, 'ES2022'],
638
+ types: [this.customType, 'node'],
639
+ baseUrl: 'src',
640
+ outDir: 'build',
641
+ sourceMap: false,
642
+ strict: true,
643
+ noImplicitAny: true,
644
+ noImplicitReturns: true,
645
+ noUnusedLocals: true,
646
+ forceConsistentCasingInFileNames: true,
647
+ declaration: true,
648
+ skipLibCheck: true,
649
+ esModuleInterop: true,
650
+ moduleDetection: 'force',
651
+ allowJs: true,
652
+ resolveJsonModule: true,
653
+ experimentalDecorators: true,
654
+ },
655
+ include: [this.customInclude, './src/*.ts', './src/**/*.ts'],
656
+ };
657
+ }
439
658
  static originalTasksJson = {
440
659
  [this.randomId]: this.randomId,
441
660
  tasks: [
@@ -478,26 +697,6 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
478
697
  ],
479
698
  }, null, 4);
480
699
  }
481
- static yarnInstallDevDepsCommand = 'yarn add -D @neurodevs/generate-id@latest @neurodevs/node-tdd@latest';
482
- static abstractPackageTestPath = 'src/__tests__/AbstractPackageTest.ts';
483
- static abstractPackageTestFile = `import AbstractModuleTest from '@neurodevs/node-tdd'
484
-
485
- export default abstract class AbstractPackageTest extends AbstractModuleTest {
486
- protected static async beforeEach() {
487
- await super.beforeEach()
488
- }
489
- }
490
- `;
491
- static defaultOptions = {
492
- installDir: this.installDir,
493
- name: this.name,
494
- description: this.description,
495
- gitNamespace: this.gitNamespace,
496
- npmNamespace: this.npmNamespace,
497
- keywords: this.keywords,
498
- license: this.license,
499
- author: this.author,
500
- };
501
700
  static NpmAutopackage(options) {
502
701
  return NpmAutopackage.Create({ ...this.defaultOptions, ...options });
503
702
  }
@@ -511,15 +710,9 @@ __decorate([
511
710
  __decorate([
512
711
  test()
513
712
  ], NpmAutopackageTest, "firstCreateRepoInGithubOrg", null);
514
- __decorate([
515
- test()
516
- ], NpmAutopackageTest, "thenChdirToInstallDir", null);
517
713
  __decorate([
518
714
  test()
519
715
  ], NpmAutopackageTest, "thenGitClone", null);
520
- __decorate([
521
- test()
522
- ], NpmAutopackageTest, "thenChdirToPackageDir", null);
523
716
  __decorate([
524
717
  test()
525
718
  ], NpmAutopackageTest, "thenGitFetchOrigin", null);
@@ -547,6 +740,12 @@ __decorate([
547
740
  __decorate([
548
741
  test()
549
742
  ], NpmAutopackageTest, "thenCommitUpdateGitignore", null);
743
+ __decorate([
744
+ test()
745
+ ], NpmAutopackageTest, "thenUpdatesTsconfig", null);
746
+ __decorate([
747
+ test()
748
+ ], NpmAutopackageTest, "thenCommitsUpdateTsconfig", null);
550
749
  __decorate([
551
750
  test()
552
751
  ], NpmAutopackageTest, "thenSpruceSetupVscode", null);
@@ -574,9 +773,36 @@ __decorate([
574
773
  __decorate([
575
774
  test()
576
775
  ], NpmAutopackageTest, "thenCommitsInstallAbstractPackageTest", null);
776
+ __decorate([
777
+ test()
778
+ ], NpmAutopackageTest, "thenInstallsEslintConfigFile", null);
779
+ __decorate([
780
+ test()
781
+ ], NpmAutopackageTest, "thenCommitsInstallEslintConfigFile", null);
782
+ __decorate([
783
+ test()
784
+ ], NpmAutopackageTest, "thenInstallsPrettierConfigFile", null);
785
+ __decorate([
786
+ test()
787
+ ], NpmAutopackageTest, "thenCommitsInstallPrettierConfigFile", null);
577
788
  __decorate([
578
789
  test()
579
790
  ], NpmAutopackageTest, "lastlyOpensVscodeAtEnd", null);
791
+ __decorate([
792
+ test()
793
+ ], NpmAutopackageTest, "installsDevDependenciesIfGenerateIdNotLatest", null);
794
+ __decorate([
795
+ test()
796
+ ], NpmAutopackageTest, "installsDevDependenciesIfNodeTddNotLatest", null);
797
+ __decorate([
798
+ test()
799
+ ], NpmAutopackageTest, "installsDevDependenciesIfEslintConfigNdxNotLatest", null);
800
+ __decorate([
801
+ test()
802
+ ], NpmAutopackageTest, "installsDevDependenciesIfPrettierConfigNdxNotLatest", null);
803
+ __decorate([
804
+ test()
805
+ ], NpmAutopackageTest, "makeNpmNamespaceOptional", null);
580
806
  __decorate([
581
807
  test()
582
808
  ], NpmAutopackageTest, "doesNotCreateRepoInGithubOrgIfDone", null);
@@ -598,6 +824,9 @@ __decorate([
598
824
  __decorate([
599
825
  test()
600
826
  ], NpmAutopackageTest, "doesNotCommitUpdateGitignoreIfDone", null);
827
+ __decorate([
828
+ test()
829
+ ], NpmAutopackageTest, "doesNotCommitUpdateTsconfigIfDone", null);
601
830
  __decorate([
602
831
  test()
603
832
  ], NpmAutopackageTest, "doesNotCommitSetupVscodeIfDone", null);
@@ -610,12 +839,6 @@ __decorate([
610
839
  __decorate([
611
840
  test()
612
841
  ], NpmAutopackageTest, "doesNotOpenVscodeIfNotCloned", null);
613
- __decorate([
614
- test()
615
- ], NpmAutopackageTest, "installsDevDependenciesIfGenerateIdNotLatest", null);
616
- __decorate([
617
- test()
618
- ], NpmAutopackageTest, "installsDevDependenciesIfNodeTddNotLatest", null);
619
842
  __decorate([
620
843
  test()
621
844
  ], NpmAutopackageTest, "doesNotThrowIfGenerateIdNotInPackageJson", null);
@@ -627,5 +850,8 @@ __decorate([
627
850
  ], NpmAutopackageTest, "doesNotInstallAbstractPackageTestIfTsxExists", null);
628
851
  __decorate([
629
852
  test()
630
- ], NpmAutopackageTest, "makeNpmNamespaceOptional", null);
853
+ ], NpmAutopackageTest, "doesNotInstallEslintConfigFileIfExists", null);
854
+ __decorate([
855
+ test()
856
+ ], NpmAutopackageTest, "doesNotInstallPrettierConfigFileIfExists", null);
631
857
  //# sourceMappingURL=NpmAutopackage.test.js.map