@atomicsmash/init-testing 1.0.0-beta.0 → 1.0.0-beta.2
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.
- package/dist/cli.js +35 -15
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +15 -7
- package/package.json +1 -1
- package/toCopy/tests/.eslintrc.cjs +9 -0
- package/toCopy/tests/fixtures/testData.ts +10 -10
- package/toCopy/tests/mocks/index.ts +10 -10
- package/toCopy/tests/tsconfig.json +5 -0
package/dist/cli.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFile, writeFile, readdir, appendFile } from "node:fs/promises";
|
|
3
|
-
import {
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { readFile, writeFile, readdir, appendFile, mkdir, } from "node:fs/promises";
|
|
3
|
+
import { resolve as pathResolve, relative as pathRelative } from "node:path";
|
|
5
4
|
import yargs from "yargs";
|
|
6
5
|
import { hideBin } from "yargs/helpers";
|
|
7
6
|
import { PackageManager } from "./utils.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const packageManager = new PackageManager(await import(`${process.cwd()}/package.json`, {
|
|
8
|
+
with: { type: "json" },
|
|
9
|
+
})
|
|
10
|
+
.then((module) => module.default)
|
|
11
|
+
.catch((error) => {
|
|
12
|
+
console.log({ error });
|
|
13
13
|
throw new Error("Unable to find package.json in your cwd. Make sure you're running this command in the right folder.");
|
|
14
|
-
}), await import(`${process.cwd()}/package-lock.json
|
|
14
|
+
}), await import(`${process.cwd()}/package-lock.json`, {
|
|
15
|
+
with: { type: "json" },
|
|
16
|
+
})
|
|
17
|
+
.then((module) => module.default)
|
|
18
|
+
.catch((error) => {
|
|
19
|
+
console.log({ error });
|
|
15
20
|
throw new Error("Unable to find package-lock.json in your cwd. Make sure you're running this command in the right folder.");
|
|
16
21
|
}));
|
|
17
22
|
const argv = await yargs(hideBin(process.argv))
|
|
@@ -21,6 +26,11 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
21
26
|
describe: "Base URL to use in actions like `await page.goto('/')`",
|
|
22
27
|
type: "string",
|
|
23
28
|
},
|
|
29
|
+
"overwrite-files": {
|
|
30
|
+
boolean: true,
|
|
31
|
+
default: false,
|
|
32
|
+
describe: "If present, will overwrite existing files when copying.",
|
|
33
|
+
},
|
|
24
34
|
"no-example": {
|
|
25
35
|
boolean: true,
|
|
26
36
|
default: false,
|
|
@@ -35,12 +45,16 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
35
45
|
.showHelpOnFail(false, "Specify --help for available options")
|
|
36
46
|
.parse();
|
|
37
47
|
const fileCopies = [];
|
|
38
|
-
const
|
|
48
|
+
const copyFolder = pathResolve(import.meta.dirname, "../toCopy");
|
|
49
|
+
const copyFiles = await readdir(copyFolder, {
|
|
39
50
|
withFileTypes: true,
|
|
40
51
|
recursive: true,
|
|
41
52
|
});
|
|
42
53
|
for (const dirent of copyFiles) {
|
|
43
|
-
|
|
54
|
+
let relativePath = pathRelative(copyFolder, `${dirent.path}`);
|
|
55
|
+
if (relativePath !== "" && !relativePath.endsWith("/")) {
|
|
56
|
+
relativePath = `${relativePath}/`;
|
|
57
|
+
}
|
|
44
58
|
if (!dirent.isFile()) {
|
|
45
59
|
continue;
|
|
46
60
|
}
|
|
@@ -50,17 +64,23 @@ for (const dirent of copyFiles) {
|
|
|
50
64
|
if (argv.noUniversal && dirent.name === "universal.spec.ts") {
|
|
51
65
|
continue;
|
|
52
66
|
}
|
|
53
|
-
fileCopies.push(readFile(dirent.path
|
|
67
|
+
fileCopies.push(readFile(`${dirent.path}/${dirent.name}`, "utf8")
|
|
54
68
|
.then(async (data) => {
|
|
55
69
|
for (const [search, replace] of [
|
|
56
70
|
["%%BASE_URL%%", argv.baseUrl],
|
|
57
71
|
]) {
|
|
58
72
|
data = data.replace(search, replace);
|
|
59
73
|
}
|
|
60
|
-
await
|
|
61
|
-
|
|
74
|
+
await mkdir(`${process.cwd()}/${relativePath}`.slice(0, -1), {
|
|
75
|
+
recursive: true,
|
|
76
|
+
});
|
|
77
|
+
await writeFile(`${process.cwd()}/${relativePath}${dirent.name}`, data, {
|
|
78
|
+
encoding: "utf8",
|
|
79
|
+
flag: argv.overwriteFiles ? "w" : "wx",
|
|
80
|
+
});
|
|
81
|
+
return `${relativePath}/${dirent.name} copied successfully.`;
|
|
62
82
|
})
|
|
63
|
-
.catch((error) => `${dirent.name} failed to copy. Error: ${error}`));
|
|
83
|
+
.catch((error) => `${relativePath}/${dirent.name} failed to copy. Error: ${error}`));
|
|
64
84
|
}
|
|
65
85
|
await Promise.all([
|
|
66
86
|
Promise.allSettled([
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAqBA,qBAAa,cAAc;IAC1B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,eAAe,CAAkB;IACzC,QAAQ;QACP;;WAEG;;QAEH;;WAEG;;QAEH;;WAEG;;MAEF;gBAEU,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;IAK1D;;OAEG;IACH,WAAW;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAqBA,qBAAa,cAAc;IAC1B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,eAAe,CAAkB;IACzC,QAAQ;QACP;;WAEG;;QAEH;;WAEG;;QAEH;;WAEG;;MAEF;gBAEU,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;IAK1D;;OAEG;IACH,WAAW;IA2BX;;;;OAIG;IACH,iBAAiB,CAAC,WAAW,EAAE,MAAM;;;;;;;;;IA2BrC;;;;;;;;OAQG;IACG,wBAAwB,CAC7B,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;QACT,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;KACxB;CAkGF"}
|
package/dist/utils.js
CHANGED
|
@@ -25,11 +25,19 @@ export class PackageManager {
|
|
|
25
25
|
* Run all the queued commands and then clear the commands object.
|
|
26
26
|
*/
|
|
27
27
|
runCommands() {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (this.commands.basic.length > 0) {
|
|
29
|
+
for (const basicCommand of this.commands.basic) {
|
|
30
|
+
exec(basicCommand);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (this.commands.install.length > 0) {
|
|
34
|
+
const installCommand = `npm install --save ${this.commands.install.join(" ")}`;
|
|
35
|
+
exec(installCommand);
|
|
36
|
+
}
|
|
37
|
+
if (this.commands.devInstall.length > 0) {
|
|
38
|
+
const devInstallCommand = `npm install --save-dev ${this.commands.devInstall.join(" ")}`;
|
|
39
|
+
exec(devInstallCommand);
|
|
30
40
|
}
|
|
31
|
-
exec(`npm install --save ${this.commands.install.join(" ")}`);
|
|
32
|
-
exec(`npm install --save-dev ${this.commands.devInstall.join(" ")}`);
|
|
33
41
|
this.commands = {
|
|
34
42
|
basic: [],
|
|
35
43
|
install: [],
|
|
@@ -86,7 +94,7 @@ export class PackageManager {
|
|
|
86
94
|
if (type === "dev") {
|
|
87
95
|
if (dependencyInfo === null) {
|
|
88
96
|
console.log(`${packageName} is missing, we will automatically install it for you.`);
|
|
89
|
-
this.commands.devInstall.push(`${packageName}
|
|
97
|
+
this.commands.devInstall.push(`${packageName}@"${packageConstraintRange}"`);
|
|
90
98
|
return resolve(true);
|
|
91
99
|
}
|
|
92
100
|
if (greaterThanRange(dependencyInfo.currentVersion, packageConstraintRange)) {
|
|
@@ -102,7 +110,7 @@ export class PackageManager {
|
|
|
102
110
|
}
|
|
103
111
|
if (dependencyInfo === null) {
|
|
104
112
|
console.log(`${packageName} is missing, we will automatically install it for you.`);
|
|
105
|
-
this.commands.install.push(`${packageName}
|
|
113
|
+
this.commands.install.push(`${packageName}@"${packageConstraintRange}"`);
|
|
106
114
|
return resolve(true);
|
|
107
115
|
}
|
|
108
116
|
const isFoundAsDevDependency = dependencyInfo.type === "dev";
|
|
@@ -120,7 +128,7 @@ export class PackageManager {
|
|
|
120
128
|
}
|
|
121
129
|
if (isFoundAsDevDependency) {
|
|
122
130
|
console.log(`An acceptable version of ${packageName} is already installed, updating it to a normal dependency...`);
|
|
123
|
-
this.commands.install.push(`${packageName}
|
|
131
|
+
this.commands.install.push(`${packageName}@"${packageConstraintRange}"`);
|
|
124
132
|
return resolve(true);
|
|
125
133
|
}
|
|
126
134
|
console.log(`An acceptable version of ${packageName} is already installed, skipping...`);
|
package/package.json
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* this could include any data you want.
|
|
5
5
|
*/
|
|
6
6
|
const phoneNumbers = [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
]
|
|
7
|
+
"01234567890",
|
|
8
|
+
"+441234567890",
|
|
9
|
+
"00441234567890",
|
|
10
|
+
"0123 45 6789",
|
|
11
|
+
"0123456789",
|
|
12
|
+
"0123456789",
|
|
13
|
+
"(01234) 567 890",
|
|
14
|
+
];
|
|
15
15
|
|
|
16
16
|
export const testData = {
|
|
17
|
-
|
|
18
|
-
}
|
|
17
|
+
phoneNumbers,
|
|
18
|
+
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { RequestHandler } from
|
|
2
|
-
import closeWithGrace from
|
|
3
|
-
import { http } from
|
|
4
|
-
import { setupServer } from
|
|
1
|
+
import type { RequestHandler } from "msw";
|
|
2
|
+
import closeWithGrace from "close-with-grace";
|
|
3
|
+
import { http } from "msw";
|
|
4
|
+
import { setupServer } from "msw/node";
|
|
5
5
|
|
|
6
|
-
const handlers: RequestHandler[] = []
|
|
6
|
+
const handlers: RequestHandler[] = [];
|
|
7
7
|
|
|
8
|
-
const server = setupServer(...handlers)
|
|
8
|
+
const server = setupServer(...handlers);
|
|
9
9
|
|
|
10
|
-
server.listen({ onUnhandledRequest:
|
|
10
|
+
server.listen({ onUnhandledRequest: "warn" });
|
|
11
11
|
// eslint-disable-next-line no-console
|
|
12
|
-
console.info(
|
|
12
|
+
console.info("🔶 Mock server installed");
|
|
13
13
|
|
|
14
14
|
closeWithGrace({ delay: 1000 }, () => {
|
|
15
|
-
|
|
16
|
-
})
|
|
15
|
+
server.close();
|
|
16
|
+
});
|