@simplysm/sd-cli 14.0.63 → 14.0.65
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/capacitor/capacitor-android.d.ts +2 -0
- package/dist/capacitor/capacitor-android.d.ts.map +1 -1
- package/dist/capacitor/capacitor-android.js +13 -0
- package/dist/capacitor/capacitor-android.js.map +1 -1
- package/dist/capacitor/capacitor-npm-config.d.ts.map +1 -1
- package/dist/capacitor/capacitor-npm-config.js +2 -6
- package/dist/capacitor/capacitor-npm-config.js.map +1 -1
- package/dist/electron/electron.d.ts.map +1 -1
- package/dist/electron/electron.js +1 -2
- package/dist/electron/electron.js.map +1 -1
- package/package.json +8 -8
- package/src/capacitor/capacitor-android.ts +14 -0
- package/src/capacitor/capacitor-npm-config.ts +2 -6
- package/src/electron/electron.ts +1 -2
- package/tests/angular/ngtsc-build-core.acc.spec.ts +36 -94
- package/tests/capacitor/capacitor-android.spec.ts +65 -28
- package/tests/capacitor/capacitor-build.spec.ts +40 -385
- package/tests/capacitor/capacitor-config-writer.acc.spec.ts +3 -17
- package/tests/capacitor/capacitor-config-writer.spec.ts +3 -17
- package/tests/capacitor/capacitor-init.spec.ts +40 -636
- package/tests/capacitor/capacitor-npm-config.acc.spec.ts +38 -168
- package/tests/capacitor/capacitor-npm-config.spec.ts +33 -71
- package/tests/commands/check.spec.ts +25 -36
- package/tests/commands/deployment-phase.acc.spec.ts +17 -26
- package/tests/commands/git-phase.acc.spec.ts +13 -112
- package/tests/commands/lint.spec.ts +7 -24
- package/tests/commands/post-publish-phase.acc.spec.ts +5 -10
- package/tests/commands/typecheck.spec.ts +43 -65
- package/tests/electron/electron.spec.ts +22 -46
- package/tests/engines/base-engine.spec.ts +4 -13
- package/tests/engines/engine-selection.spec.ts +14 -17
- package/tests/engines/engine-typecheck-selection.acc.spec.ts +13 -16
- package/tests/engines/esbuild-client-engine.acc.spec.ts +36 -40
- package/tests/engines/esbuild-client-engine.spec.ts +4 -23
- package/tests/engines/ngtsc-engine.spec.ts +3 -10
- package/tests/engines/server-esbuild-engine.spec.ts +3 -10
- package/tests/engines/tsc-engine.spec.ts +3 -10
- package/tests/esbuild/esbuild-tsc-plugin.acc.spec.ts +3 -8
- package/tests/esbuild/esbuild-tsc-plugin.spec.ts +3 -8
- package/tests/orchestrators/build-orchestrator.spec.ts +57 -102
- package/tests/orchestrators/dev-orchestrator.spec.ts +68 -109
- package/tests/orchestrators/typecheck-orchestrator.spec.ts +25 -57
- package/tests/orchestrators/watch-orchestrator.spec.ts +73 -99
- package/tests/sd-cli-entry.spec.ts +17 -20
- package/tests/utils/angular-source-file-cache.spec.ts +4 -8
- package/tests/utils/copy-src.spec.ts +9 -20
- package/tests/utils/esbuild-client-config.acc.spec.ts +9 -15
- package/tests/utils/esbuild-client-config.spec.ts +12 -24
- package/tests/utils/esbuild-config.spec.ts +51 -42
- package/tests/utils/lint-core.spec.ts +13 -19
- package/tests/utils/lint-utils.spec.ts +8 -15
- package/tests/utils/lint-with-program.spec.ts +3 -7
- package/tests/utils/ngtsc-build-core.spec.ts +2 -99
- package/tests/utils/orchestrator-utils.spec.ts +7 -20
- package/tests/utils/output-utils.spec.ts +5 -11
- package/tests/utils/sd-config.spec.ts +4 -12
- package/tests/utils/typecheck-env.spec.ts +49 -77
- package/tests/utils/typecheck-non-package.spec.ts +23 -16
- package/tests/workers/build-watch-paths.acc.spec.ts +4 -10
- package/tests/workers/build-watch-paths.spec.ts +4 -9
- package/tests/workers/client-worker.acc.spec.ts +64 -137
- package/tests/workers/client-worker.spec.ts +63 -89
- package/tests/workers/library-build-lint.spec.ts +19 -30
- package/tests/workers/library-build-worker.spec.ts +28 -55
- package/tests/workers/server-esbuild-context.acc.spec.ts +6 -15
- package/tests/workers/server-esbuild-context.spec.ts +7 -16
- package/tests/workers/server-runtime-worker.spec.ts +8 -10
- package/tests/workers/shared-worker-lifecycle.acc.spec.ts +3 -5
- package/tests/workers/shared-worker-lifecycle.spec.ts +4 -5
- package/tests/capacitor/capacitor-icon.spec.ts +0 -285
- package/tests/capacitor/capacitor-run.spec.ts +0 -256
- package/tests/capacitor/capacitor-workspace.spec.ts +0 -203
- package/tests/commands/device.spec.ts +0 -237
- package/tests/commands/publish.spec.ts +0 -1183
- package/tests/utils/external-modules.spec.ts +0 -217
- package/tests/workers/server-build-lint.spec.ts +0 -201
- package/tests/workers/server-build-worker.spec.ts +0 -765
- package/tests/workers/server-watch-manager.acc.spec.ts +0 -162
- package/tests/workers/server-watch-manager.spec.ts +0 -199
|
@@ -1,104 +1,78 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { describe, it, expect, vi, beforeAll, afterAll, beforeEach } from "vitest";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
import * as coreNode from "@simplysm/core-node";
|
|
7
|
+
import * as sharedWorkerLifecycle from "../../src/workers/shared-worker-lifecycle";
|
|
8
|
+
import * as esbuildClientConfig from "../../src/esbuild/esbuild-client-config";
|
|
9
|
+
import * as esbuildIndexHtml from "../../src/esbuild/esbuild-index-html";
|
|
10
|
+
import * as esbuildPwa from "../../src/esbuild/esbuild-pwa";
|
|
11
|
+
import * as devHttpServer from "../../src/dev-server/dev-http-server";
|
|
12
|
+
import * as hmrService from "../../src/dev-server/hmr-service";
|
|
13
|
+
import * as hmrClientScript from "../../src/dev-server/hmr-client-script";
|
|
14
|
+
import * as copyPublic from "../../src/utils/copy-public";
|
|
15
|
+
import * as sdConfig from "../../src/utils/sd-config";
|
|
4
16
|
|
|
5
17
|
let workerFns: Record<string, (...args: any[]) => any>;
|
|
6
18
|
let mockSend: ReturnType<typeof vi.fn>;
|
|
7
19
|
|
|
8
20
|
const mockRebuild = vi.fn();
|
|
9
21
|
const mockDispose = vi.fn();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
vi.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
applyPwa: vi.fn(() => Promise.resolve()),
|
|
45
|
-
createPwaHtmlTransform: vi.fn(),
|
|
46
|
-
}));
|
|
47
|
-
|
|
48
|
-
vi.mock("../../src/dev-server/dev-http-server", () => ({
|
|
49
|
-
createDevHttpServer: vi.fn(),
|
|
50
|
-
}));
|
|
51
|
-
|
|
52
|
-
vi.mock("../../src/dev-server/hmr-service", () => ({
|
|
53
|
-
createHmrService: vi.fn(),
|
|
54
|
-
}));
|
|
55
|
-
|
|
56
|
-
vi.mock("../../src/dev-server/hmr-client-script", () => ({
|
|
57
|
-
createHmrPostTransform: vi.fn(),
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
vi.mock("../../src/utils/copy-public", () => ({
|
|
61
|
-
copyPublicFiles: vi.fn(() => Promise.resolve()),
|
|
62
|
-
watchPublicFiles: vi.fn(),
|
|
63
|
-
}));
|
|
64
|
-
|
|
65
|
-
vi.mock("../../src/utils/sd-config", () => ({
|
|
66
|
-
loadSdConfig: vi.fn(() =>
|
|
67
|
-
Promise.resolve({
|
|
68
|
-
packages: { "my-app": { target: "client", server: "my-server" } },
|
|
69
|
-
}),
|
|
70
|
-
),
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
vi.mock("node:fs", () => ({
|
|
74
|
-
default: {
|
|
75
|
-
readFileSync: (...args: any[]) => mockReadFileSync(...args),
|
|
76
|
-
writeFileSync: vi.fn(),
|
|
77
|
-
existsSync: (...args: any[]) => mockExistsSync(...args),
|
|
78
|
-
mkdirSync: vi.fn(),
|
|
79
|
-
rmSync: vi.fn(),
|
|
80
|
-
},
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
22
|
+
|
|
23
|
+
vi.spyOn(coreNode, "createWorker").mockImplementation((fns: Record<string, Function>) => {
|
|
24
|
+
workerFns = fns as any;
|
|
25
|
+
mockSend = vi.fn();
|
|
26
|
+
return { send: mockSend } as any;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
vi.spyOn(sharedWorkerLifecycle, "setupWorkerLifecycle").mockImplementation(() => ({
|
|
30
|
+
logger: { debug: vi.fn(), error: vi.fn(), warn: vi.fn() },
|
|
31
|
+
guardStartWatch: vi.fn(),
|
|
32
|
+
}) as any);
|
|
33
|
+
|
|
34
|
+
vi.spyOn(esbuildClientConfig, "createClientEsbuildContext").mockResolvedValue({
|
|
35
|
+
context: { rebuild: mockRebuild, dispose: mockDispose, watch: vi.fn() },
|
|
36
|
+
sourceFileCache: {},
|
|
37
|
+
} as any);
|
|
38
|
+
|
|
39
|
+
vi.spyOn(esbuildIndexHtml, "generateIndexHtml").mockResolvedValue({
|
|
40
|
+
content: "<html></html>", errors: [], warnings: [],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
vi.spyOn(esbuildPwa, "applyPwa").mockResolvedValue(undefined);
|
|
44
|
+
vi.spyOn(esbuildPwa, "createPwaHtmlTransform").mockReturnValue(undefined as any);
|
|
45
|
+
|
|
46
|
+
vi.spyOn(devHttpServer, "createDevHttpServer").mockReturnValue(undefined as any);
|
|
47
|
+
vi.spyOn(hmrService, "createHmrService").mockReturnValue(undefined as any);
|
|
48
|
+
vi.spyOn(hmrClientScript, "createHmrPostTransform").mockReturnValue(undefined as any);
|
|
49
|
+
|
|
50
|
+
vi.spyOn(copyPublic, "copyPublicFiles").mockResolvedValue(undefined);
|
|
51
|
+
vi.spyOn(copyPublic, "watchPublicFiles").mockReturnValue(undefined as any);
|
|
52
|
+
|
|
53
|
+
vi.spyOn(sdConfig, "loadSdConfig").mockResolvedValue({
|
|
54
|
+
packages: { "my-app": { target: "client", server: "my-server" } },
|
|
55
|
+
} as any);
|
|
84
56
|
|
|
85
57
|
await import("../../src/workers/client.worker");
|
|
86
58
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
59
|
+
let tmpRoot: string;
|
|
60
|
+
let baseBuildInfo: { name: string; cwd: string; pkgDir: string };
|
|
61
|
+
|
|
62
|
+
beforeAll(() => {
|
|
63
|
+
tmpRoot = mkdtempSync(path.join(tmpdir(), "client-worker-"));
|
|
64
|
+
const pkgDir = path.join(tmpRoot, "packages", "my-app");
|
|
65
|
+
mkdirSync(pkgDir, { recursive: true });
|
|
66
|
+
writeFileSync(path.join(pkgDir, "package.json"), JSON.stringify({ name: "@scope/my-app" }));
|
|
67
|
+
baseBuildInfo = { name: "my-app", cwd: tmpRoot, pkgDir };
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
afterAll(() => {
|
|
71
|
+
rmSync(tmpRoot, { recursive: true, force: true });
|
|
72
|
+
});
|
|
92
73
|
|
|
93
74
|
beforeEach(() => {
|
|
94
75
|
vi.clearAllMocks();
|
|
95
|
-
mockReadFileSync.mockImplementation((filePath: any) => {
|
|
96
|
-
if (String(filePath).endsWith("package.json")) {
|
|
97
|
-
return JSON.stringify({ name: "@scope/my-app" });
|
|
98
|
-
}
|
|
99
|
-
return "";
|
|
100
|
-
});
|
|
101
|
-
mockExistsSync.mockReturnValue(false);
|
|
102
76
|
mockRebuild.mockResolvedValue({
|
|
103
77
|
metafile: { outputs: {} },
|
|
104
78
|
errors: [],
|
|
@@ -1,39 +1,28 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return {
|
|
3
|
+
import * as coreNode from "@simplysm/core-node";
|
|
4
|
+
import * as sdTsCompilerMod from "../../src/ts-compiler/SdTsCompiler";
|
|
5
|
+
import * as sharedWorkerLifecycle from "../../src/workers/shared-worker-lifecycle";
|
|
6
|
+
import * as collectDepsMod from "../../src/deps/replace-deps/collect-deps";
|
|
7
|
+
|
|
8
|
+
const mockCompileAsync = vi.fn();
|
|
9
|
+
const MockSdTsCompiler = vi.fn().mockImplementation(function () {
|
|
10
|
+
return { compileAsync: mockCompileAsync };
|
|
11
11
|
});
|
|
12
|
+
vi.spyOn(sdTsCompilerMod, "SdTsCompiler" as any).mockImplementation(MockSdTsCompiler as any);
|
|
12
13
|
|
|
13
|
-
vi.
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
vi.spyOn(sharedWorkerLifecycle, "setupWorkerLifecycle").mockImplementation(() => ({
|
|
15
|
+
logger: { debug: vi.fn(), warn: vi.fn() },
|
|
16
|
+
guardStartWatch: vi.fn(),
|
|
17
|
+
}) as any);
|
|
16
18
|
|
|
17
|
-
vi.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
vi.mock("@simplysm/core-node", () => ({
|
|
25
|
-
createWorker: vi.fn(
|
|
26
|
-
(methods: Record<string, Function>) => {
|
|
27
|
-
Object.assign(workerMethods, methods);
|
|
28
|
-
return { send: vi.fn() };
|
|
29
|
-
},
|
|
30
|
-
),
|
|
31
|
-
FsWatcher: { watch: vi.fn() },
|
|
32
|
-
}));
|
|
19
|
+
vi.spyOn(coreNode, "createWorker").mockImplementation((methods: Record<string, Function>) => {
|
|
20
|
+
Object.assign(workerMethods, methods);
|
|
21
|
+
return { send: vi.fn() } as any;
|
|
22
|
+
});
|
|
23
|
+
vi.spyOn(coreNode.FsWatcher, "watch").mockImplementation(() => Promise.resolve(undefined as any));
|
|
33
24
|
|
|
34
|
-
vi.
|
|
35
|
-
collectDeps: vi.fn(() => ({ workspaceDeps: [], replaceDeps: [] })),
|
|
36
|
-
}));
|
|
25
|
+
vi.spyOn(collectDepsMod, "collectDeps").mockReturnValue({ workspaceDeps: [], replaceDeps: [] });
|
|
37
26
|
|
|
38
27
|
const defaultCompileResult = {
|
|
39
28
|
program: { getSourceFiles: () => [] },
|
|
@@ -1,80 +1,53 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import * as collectDepsModule from "../../src/deps/replace-deps/collect-deps";
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
import * as coreNode from "@simplysm/core-node";
|
|
5
|
+
import * as collectDepsModule from "../../src/deps/replace-deps/collect-deps";
|
|
6
|
+
import * as sdTsCompilerMod from "../../src/ts-compiler/SdTsCompiler";
|
|
7
|
+
import * as ngtscBuildCore from "../../src/angular/ngtsc-build-core";
|
|
8
|
+
import * as sharedWorkerLifecycle from "../../src/workers/shared-worker-lifecycle";
|
|
6
9
|
|
|
7
10
|
let workerFns: Record<string, (...args: any[]) => any>;
|
|
8
11
|
let mockSend: ReturnType<typeof vi.fn>;
|
|
9
12
|
|
|
10
|
-
// FsWatcher mock
|
|
11
13
|
const mockOnChange = vi.fn();
|
|
12
14
|
const mockWatcherClose = vi.fn();
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.compileAsync = compileAsync;
|
|
20
|
-
this.sideEffectScssRegistry = sideEffectScssRegistry;
|
|
21
|
-
});
|
|
22
|
-
return { mockCompileAsync: compileAsync, MockSdTsCompiler: Compiler, mockSideEffectScssRegistry: sideEffectScssRegistry };
|
|
16
|
+
const mockCompileAsync = vi.fn();
|
|
17
|
+
const mockSideEffectScssRegistry = new Map();
|
|
18
|
+
const MockSdTsCompiler = vi.fn().mockImplementation(function (this: any) {
|
|
19
|
+
this.compileAsync = mockCompileAsync;
|
|
20
|
+
this.sideEffectScssRegistry = mockSideEffectScssRegistry;
|
|
23
21
|
});
|
|
22
|
+
vi.spyOn(sdTsCompilerMod, "SdTsCompiler" as any).mockImplementation(MockSdTsCompiler as any);
|
|
24
23
|
|
|
25
|
-
vi.
|
|
26
|
-
|
|
27
|
-
}));
|
|
24
|
+
const mockWriteEmitResults = vi.spyOn(ngtscBuildCore, "writeEmitResults").mockImplementation(() => undefined);
|
|
25
|
+
const mockCompileSideEffectScss = vi.spyOn(ngtscBuildCore, "compileSideEffectScss").mockImplementation(() => undefined);
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
vi.spyOn(coreNode, "createWorker").mockImplementation((fns: Record<string, Function>) => {
|
|
28
|
+
workerFns = fns as any;
|
|
29
|
+
mockSend = vi.fn();
|
|
30
|
+
return { send: mockSend } as any;
|
|
32
31
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
vi.mock("@simplysm/core-node", () => ({
|
|
44
|
-
createWorker: vi.fn((fns: Record<string, Function>) => {
|
|
45
|
-
workerFns = fns as any;
|
|
46
|
-
mockSend = vi.fn();
|
|
47
|
-
return { send: mockSend };
|
|
48
|
-
}),
|
|
49
|
-
FsWatcher: {
|
|
50
|
-
watch: vi.fn(() => Promise.resolve({
|
|
51
|
-
onChange: mockOnChange,
|
|
52
|
-
close: mockWatcherClose,
|
|
53
|
-
})),
|
|
54
|
-
},
|
|
55
|
-
pathx: {
|
|
56
|
-
posix: vi.fn((p: string) => p.replace(/\\/g, "/")),
|
|
57
|
-
posixResolve: vi.fn((...args: string[]) => path.resolve(...args).replace(/\\/g, "/")),
|
|
58
|
-
},
|
|
59
|
-
}));
|
|
32
|
+
vi.spyOn(coreNode.FsWatcher, "watch").mockImplementation(() =>
|
|
33
|
+
Promise.resolve({ onChange: mockOnChange, close: mockWatcherClose } as any),
|
|
34
|
+
);
|
|
35
|
+
vi.spyOn(coreNode.pathx, "posix").mockImplementation((p: string) => p.replace(/\\/g, "/") as coreNode.pathx.PosixPath);
|
|
36
|
+
vi.spyOn(coreNode.pathx, "posixResolve").mockImplementation(
|
|
37
|
+
(...args: string[]) => path.resolve(...args).replace(/\\/g, "/") as coreNode.pathx.PosixPath,
|
|
38
|
+
);
|
|
60
39
|
|
|
61
40
|
const mockDebug = vi.fn();
|
|
41
|
+
vi.spyOn(sharedWorkerLifecycle, "setupWorkerLifecycle").mockImplementation(() => ({
|
|
42
|
+
logger: { debug: mockDebug, warn: vi.fn() },
|
|
43
|
+
guardStartWatch: vi.fn(),
|
|
44
|
+
}) as any);
|
|
62
45
|
|
|
63
|
-
vi.mock("../../src/workers/shared-worker-lifecycle", () => ({
|
|
64
|
-
setupWorkerLifecycle: vi.fn(() => ({
|
|
65
|
-
logger: { debug: mockDebug, warn: vi.fn() },
|
|
66
|
-
guardStartWatch: vi.fn(),
|
|
67
|
-
})),
|
|
68
|
-
}));
|
|
69
|
-
|
|
70
|
-
// collect-deps spy
|
|
71
46
|
const mockCollectDeps = vi.spyOn(collectDepsModule, "collectDeps").mockReturnValue({
|
|
72
47
|
workspaceDeps: [],
|
|
73
48
|
replaceDeps: [],
|
|
74
49
|
});
|
|
75
50
|
|
|
76
|
-
//#endregion
|
|
77
|
-
|
|
78
51
|
const defaultCompileResult = {
|
|
79
52
|
program: { getSourceFiles: () => [{ fileName: "/pkg/src/index.ts" }] },
|
|
80
53
|
builderProgram: {},
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
2
2
|
|
|
3
|
-
//#region Mocks
|
|
4
|
-
|
|
5
3
|
const mockRebuild = vi.fn();
|
|
6
4
|
const mockDispose = vi.fn();
|
|
7
5
|
|
|
@@ -14,6 +12,7 @@ const mockTscPlugin = {
|
|
|
14
12
|
resetBuilderProgram: vi.fn(),
|
|
15
13
|
};
|
|
16
14
|
|
|
15
|
+
// esbuild는 외부 npm으로 ESM namespace immutable이라 vi.mock 유지
|
|
17
16
|
vi.mock("esbuild", () => ({
|
|
18
17
|
default: {
|
|
19
18
|
context: vi.fn(() =>
|
|
@@ -24,26 +23,18 @@ vi.mock("esbuild", () => ({
|
|
|
24
23
|
messages.map((m) => m.text),
|
|
25
24
|
}));
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
...actual,
|
|
31
|
-
writeChangedOutputFiles: vi.fn(() => Promise.resolve()),
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
vi.mock("../../src/esbuild/esbuild-tsc-plugin", () => ({
|
|
36
|
-
createTscPlugin: vi.fn(() => mockTscPlugin),
|
|
37
|
-
}));
|
|
26
|
+
import * as esbuildConfigMod from "../../src/esbuild/esbuild-config";
|
|
27
|
+
import * as tscPluginMod from "../../src/esbuild/esbuild-tsc-plugin";
|
|
38
28
|
|
|
39
|
-
|
|
29
|
+
vi.spyOn(esbuildConfigMod, "writeChangedOutputFiles").mockResolvedValue(undefined);
|
|
30
|
+
vi.spyOn(tscPluginMod, "createTscPlugin").mockReturnValue(mockTscPlugin as any);
|
|
40
31
|
|
|
41
32
|
const esbuild = (await import("esbuild")).default;
|
|
33
|
+
const { createTscPlugin } = tscPluginMod;
|
|
42
34
|
const {
|
|
43
35
|
createContext, rebuild, recreateContext, dispose, getMetafile, hasContext,
|
|
44
36
|
getTscProgram, getTscAffectedFiles, getTscDiagnostics,
|
|
45
37
|
} = await import("../../src/workers/server-esbuild-context");
|
|
46
|
-
const { createTscPlugin } = await import("../../src/esbuild/esbuild-tsc-plugin");
|
|
47
38
|
|
|
48
39
|
const baseOptions = {
|
|
49
40
|
pkgDir: "/workspace/packages/my-server",
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
2
2
|
|
|
3
|
-
//#region Mocks
|
|
4
|
-
|
|
5
3
|
const mockRebuild = vi.fn();
|
|
6
4
|
const mockDispose = vi.fn();
|
|
7
5
|
|
|
@@ -14,6 +12,7 @@ const mockTscPlugin = {
|
|
|
14
12
|
resetBuilderProgram: vi.fn(),
|
|
15
13
|
};
|
|
16
14
|
|
|
15
|
+
// esbuild는 외부 npm으로 ESM namespace immutable이라 vi.mock 유지
|
|
17
16
|
vi.mock("esbuild", () => ({
|
|
18
17
|
default: {
|
|
19
18
|
context: vi.fn(() =>
|
|
@@ -24,27 +23,19 @@ vi.mock("esbuild", () => ({
|
|
|
24
23
|
messages.map((m) => m.text),
|
|
25
24
|
}));
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
...actual,
|
|
31
|
-
writeChangedOutputFiles: vi.fn(() => Promise.resolve()),
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
vi.mock("../../src/esbuild/esbuild-tsc-plugin", () => ({
|
|
36
|
-
createTscPlugin: vi.fn(() => mockTscPlugin),
|
|
37
|
-
}));
|
|
26
|
+
import * as esbuildConfigMod from "../../src/esbuild/esbuild-config";
|
|
27
|
+
import * as tscPluginMod from "../../src/esbuild/esbuild-tsc-plugin";
|
|
38
28
|
|
|
39
|
-
|
|
29
|
+
vi.spyOn(esbuildConfigMod, "writeChangedOutputFiles").mockResolvedValue(undefined);
|
|
30
|
+
vi.spyOn(tscPluginMod, "createTscPlugin").mockReturnValue(mockTscPlugin as any);
|
|
40
31
|
|
|
41
32
|
const esbuild = (await import("esbuild")).default;
|
|
42
|
-
const { writeChangedOutputFiles } =
|
|
33
|
+
const { writeChangedOutputFiles } = esbuildConfigMod;
|
|
34
|
+
const { createTscPlugin } = tscPluginMod;
|
|
43
35
|
const {
|
|
44
36
|
createContext, rebuild, recreateContext, dispose, getMetafile, hasContext,
|
|
45
37
|
getTscProgram, getTscAffectedFiles, getTscDiagnostics,
|
|
46
38
|
} = await import("../../src/workers/server-esbuild-context");
|
|
47
|
-
const { createTscPlugin } = await import("../../src/esbuild/esbuild-tsc-plugin");
|
|
48
39
|
|
|
49
40
|
const baseOptions = {
|
|
50
41
|
pkgDir: "/workspace/packages/my-server",
|
|
@@ -9,6 +9,7 @@ import fsp from "fs/promises";
|
|
|
9
9
|
let workerFns: Record<string, (...args: any[]) => any>;
|
|
10
10
|
let mockSend: ReturnType<typeof vi.fn>;
|
|
11
11
|
|
|
12
|
+
// @simplysm/core-node createWorker는 Worker thread 부작용이 있어 mock 유지
|
|
12
13
|
vi.mock("@simplysm/core-node", () => ({
|
|
13
14
|
createWorker: vi.fn((fns: Record<string, Function>) => {
|
|
14
15
|
workerFns = fns as any;
|
|
@@ -17,18 +18,13 @@ vi.mock("@simplysm/core-node", () => ({
|
|
|
17
18
|
}),
|
|
18
19
|
}));
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
registerCleanupHandlers: vi.fn(),
|
|
22
|
-
setupWorkerConsola: vi.fn(),
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
// @fastify/http-proxy mock
|
|
21
|
+
// @fastify/http-proxy는 외부 npm으로 mock 유지
|
|
26
22
|
const mockProxyPlugin = vi.fn();
|
|
27
23
|
vi.mock("@fastify/http-proxy", () => ({
|
|
28
24
|
default: mockProxyPlugin,
|
|
29
25
|
}));
|
|
30
26
|
|
|
31
|
-
//
|
|
27
|
+
// net 표준 모듈은 ESM namespace immutable + OS 의존이라 mock 유지
|
|
32
28
|
let portCheckResults: boolean[] = [];
|
|
33
29
|
let portCheckIndex = 0;
|
|
34
30
|
|
|
@@ -43,9 +39,6 @@ vi.mock("net", () => ({
|
|
|
43
39
|
listen: () => {
|
|
44
40
|
const isAvailable = portCheckResults[portCheckIndex++] ?? true;
|
|
45
41
|
if (isAvailable) {
|
|
46
|
-
const _closeFn = (cb?: () => void) => {
|
|
47
|
-
cb?.();
|
|
48
|
-
};
|
|
49
42
|
handlers["listening"]();
|
|
50
43
|
} else {
|
|
51
44
|
handlers["error"]();
|
|
@@ -59,6 +52,11 @@ vi.mock("net", () => ({
|
|
|
59
52
|
},
|
|
60
53
|
}));
|
|
61
54
|
|
|
55
|
+
import * as workerUtils from "../../src/runtime/worker-utils";
|
|
56
|
+
|
|
57
|
+
vi.spyOn(workerUtils, "registerCleanupHandlers").mockImplementation(() => {});
|
|
58
|
+
vi.spyOn(workerUtils, "setupWorkerConsola").mockImplementation(() => {});
|
|
59
|
+
|
|
62
60
|
// Import triggers createWorker
|
|
63
61
|
await import("../../src/workers/server-runtime.worker");
|
|
64
62
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import * as coreNode from "@simplysm/core-node";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
vi.mock("@simplysm/core-node", () => ({
|
|
5
|
-
setupConsola: vi.fn(),
|
|
6
|
-
}));
|
|
4
|
+
vi.spyOn(coreNode, "setupConsola").mockImplementation(() => undefined);
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
import { setupWorkerLifecycle } from "../../src/workers/shared-worker-lifecycle";
|
|
9
7
|
|
|
10
8
|
describe("setupWorkerLifecycle", () => {
|
|
11
9
|
// Scenario: setupWorkerLifecycle 함수가 4개 초기화 단계를 통합한다
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
2
|
import { consola } from "consola";
|
|
3
|
+
import * as coreNode from "@simplysm/core-node";
|
|
3
4
|
|
|
4
|
-
// setupConsola는 consola 글로벌 상태를 변경하므로
|
|
5
|
-
vi.
|
|
6
|
-
setupConsola: vi.fn(),
|
|
7
|
-
}));
|
|
5
|
+
// setupConsola는 consola 글로벌 상태를 변경하므로 spy로 차단
|
|
6
|
+
vi.spyOn(coreNode, "setupConsola").mockImplementation(() => undefined);
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
import { setupWorkerLifecycle } from "../../src/workers/shared-worker-lifecycle";
|
|
10
9
|
|
|
11
10
|
beforeEach(() => {
|
|
12
11
|
vi.restoreAllMocks();
|