@tsed/cli-plugin-vitest 6.6.3 → 7.0.0-alpha.1
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/lib/esm/CliPluginVitestModule.js +65 -40
- package/lib/esm/index.js +0 -1
- package/lib/esm/templates/controller.integration.template.js +36 -0
- package/lib/esm/templates/decorator.class.template.js +23 -0
- package/lib/esm/templates/decorator.endpoint.template.js +27 -0
- package/lib/esm/templates/decorator.method.template.js +25 -0
- package/lib/esm/templates/decorator.param.template.js +26 -0
- package/lib/esm/templates/decorator.parameter.template.js +24 -0
- package/lib/esm/templates/decorator.prop.template.js +27 -0
- package/lib/esm/templates/decorator.property.template.js +25 -0
- package/lib/esm/templates/generic.spec.template.js +26 -0
- package/lib/esm/templates/index.js +12 -0
- package/lib/esm/templates/server.integration.template.js +31 -0
- package/{templates/init/vitest.config.mts.hbs → lib/esm/templates/vitest.config.template.js} +13 -2
- package/lib/types/CliPluginVitestModule.d.ts +7 -8
- package/lib/types/index.d.ts +0 -1
- package/lib/types/templates/controller.integration.template.d.ts +2 -0
- package/lib/types/templates/decorator.class.template.d.ts +2 -0
- package/lib/types/templates/decorator.endpoint.template.d.ts +2 -0
- package/lib/types/templates/decorator.method.template.d.ts +2 -0
- package/lib/types/templates/decorator.param.template.d.ts +2 -0
- package/lib/types/templates/decorator.parameter.template.d.ts +2 -0
- package/lib/types/templates/decorator.prop.template.d.ts +2 -0
- package/lib/types/templates/decorator.property.template.d.ts +2 -0
- package/lib/types/templates/generic.spec.template.d.ts +2 -0
- package/lib/types/templates/index.d.ts +11 -0
- package/lib/types/templates/server.integration.template.d.ts +2 -0
- package/lib/types/templates/vitest.config.template.d.ts +2 -0
- package/package.json +8 -5
- package/lib/esm/hooks/VitestGenerateHook.js +0 -60
- package/lib/esm/hooks/VitestInitHook.js +0 -32
- package/lib/esm/utils/templateDir.js +0 -2
- package/lib/types/hooks/VitestGenerateHook.d.ts +0 -7
- package/lib/types/hooks/VitestInitHook.d.ts +0 -10
- package/lib/types/utils/templateDir.d.ts +0 -1
- package/templates/generate/decorator.class.spec.hbs +0 -12
- package/templates/generate/decorator.endpoint.spec.hbs +0 -16
- package/templates/generate/decorator.method.spec.hbs +0 -14
- package/templates/generate/decorator.param.spec.hbs +0 -15
- package/templates/generate/decorator.parameter.spec.hbs +0 -13
- package/templates/generate/decorator.prop.spec.hbs +0 -16
- package/templates/generate/decorator.property.spec.hbs +0 -14
- package/templates/generate/generic.integration.hbs +0 -21
- package/templates/generate/generic.spec.hbs +0 -15
- package/templates/generate/server.integration.hbs +0 -21
|
@@ -1,43 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
// Import templates to register them with the DI container
|
|
2
|
+
import "./templates/index.js";
|
|
3
|
+
import { CliProjectService, render } from "@tsed/cli";
|
|
4
|
+
import { ProjectPackageJson } from "@tsed/cli-core";
|
|
5
|
+
import { inject, injectable } from "@tsed/di";
|
|
6
|
+
export class CliPluginVitestModule {
|
|
7
|
+
$alterPackageJson(packageJson, data) {
|
|
8
|
+
if (data.vitest) {
|
|
9
|
+
packageJson.addScripts({
|
|
10
|
+
"test:unit": "cross-env NODE_ENV=test vitest run",
|
|
11
|
+
"test:watch": "cross-env NODE_ENV=test vitest",
|
|
12
|
+
"test:coverage": `cross-env NODE_ENV=test vitest run --coverage`
|
|
13
|
+
});
|
|
14
|
+
packageJson.addDevDependencies({
|
|
15
|
+
vitest: "latest",
|
|
16
|
+
"unplugin-swc": "latest",
|
|
17
|
+
"@vitest/coverage-v8": "latest",
|
|
18
|
+
"@swc/core": "latest"
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return packageJson;
|
|
10
22
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
$alterInitSubTasks(tasks, data) {
|
|
24
|
+
return [
|
|
25
|
+
...tasks,
|
|
26
|
+
{
|
|
27
|
+
title: "Create vitest configuration",
|
|
28
|
+
enabled: () => !!data.vitest,
|
|
29
|
+
task: () => render("vitest.config", {
|
|
30
|
+
symbolName: "vitest.config"
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
];
|
|
14
34
|
}
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
$alterGenerateTasks(tasks, data) {
|
|
36
|
+
const { symbolPath } = data;
|
|
37
|
+
return [
|
|
38
|
+
...tasks,
|
|
39
|
+
{
|
|
40
|
+
title: `Generate ${data.type} spec file to '${symbolPath}.spec.ts'`,
|
|
41
|
+
enabled() {
|
|
42
|
+
return !(data.type === "server" || data.type.includes(":dataSource") || data.type.includes(":connection"));
|
|
43
|
+
},
|
|
44
|
+
task: () => {
|
|
45
|
+
let specTemplateType = [data.type, data.templateType, "spec"].filter(Boolean).join(".");
|
|
46
|
+
specTemplateType = inject(CliProjectService).templates.get(specTemplateType) ? specTemplateType : "generic.spec";
|
|
47
|
+
return render(specTemplateType, {
|
|
48
|
+
...data,
|
|
49
|
+
symbolPath: data.symbolPath + ".spec"
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
title: `Generate ${data.type} integration file '${symbolPath}.integration.spec.ts'`,
|
|
55
|
+
enabled() {
|
|
56
|
+
return ["controller", "server"].includes(data.type);
|
|
57
|
+
},
|
|
58
|
+
task: () => {
|
|
59
|
+
return render(data.type + ".integration", {
|
|
60
|
+
...data,
|
|
61
|
+
symbolPath: data.symbolPath + ".integration.spec"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
];
|
|
22
66
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
vitest: "latest",
|
|
26
|
-
"unplugin-swc": "latest",
|
|
27
|
-
"@vitest/coverage-v8": "latest",
|
|
28
|
-
"@swc/core": "latest"
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
__decorate([
|
|
33
|
-
OnAdd("@tsed/cli-plugin-vitest"),
|
|
34
|
-
__metadata("design:type", Function),
|
|
35
|
-
__metadata("design:paramtypes", []),
|
|
36
|
-
__metadata("design:returntype", void 0)
|
|
37
|
-
], CliPluginVitestModule.prototype, "install", null);
|
|
38
|
-
CliPluginVitestModule = __decorate([
|
|
39
|
-
Module({
|
|
40
|
-
imports: [VitestInitHook, VitestGenerateHook]
|
|
41
|
-
})
|
|
42
|
-
], CliPluginVitestModule);
|
|
43
|
-
export { CliPluginVitestModule };
|
|
67
|
+
}
|
|
68
|
+
injectable(CliPluginVitestModule);
|
package/lib/esm/index.js
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CliProjectService, defineTemplate } from "@tsed/cli";
|
|
2
|
+
import { inject } from "@tsed/cli-core";
|
|
3
|
+
export default defineTemplate({
|
|
4
|
+
id: "controller.integration",
|
|
5
|
+
label: "Generic Integration Test",
|
|
6
|
+
fileName: "{{symbolName}}.spec",
|
|
7
|
+
outputDir: "{{srcDir}}",
|
|
8
|
+
hidden: true,
|
|
9
|
+
render(symbolName, data) {
|
|
10
|
+
const projectService = inject(CliProjectService);
|
|
11
|
+
const relativePath = projectService.getRelativePath(`${data.symbolPath}.integration.spec.ts`);
|
|
12
|
+
const serverName = projectService.getServerFileName();
|
|
13
|
+
return `import { expect, describe, it, afterAll, beforeAll } from "vitest";
|
|
14
|
+
import { PlatformTest } from "@tsed/platform-http/testing";
|
|
15
|
+
import SuperTest from "supertest";
|
|
16
|
+
import { ${symbolName} } from "./${data.symbolPathBasename}.js";
|
|
17
|
+
import { Server } from "${relativePath}/${serverName}.js";
|
|
18
|
+
|
|
19
|
+
describe("${symbolName}", () => {
|
|
20
|
+
beforeAll(PlatformTest.bootstrap(Server, {
|
|
21
|
+
mount: {
|
|
22
|
+
"/": [${symbolName}]
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
afterAll(PlatformTest.reset);
|
|
26
|
+
|
|
27
|
+
it("should call GET ${data.route}", async () => {
|
|
28
|
+
const request = SuperTest(PlatformTest.callback());
|
|
29
|
+
const response = await request.get("${data.route}").expect(200);
|
|
30
|
+
|
|
31
|
+
expect(response.text).toEqual("hello");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
export default defineTemplate({
|
|
3
|
+
id: "decorator.class.spec",
|
|
4
|
+
label: "Class Decorator Test",
|
|
5
|
+
fileName: "{{symbolName}}.spec",
|
|
6
|
+
outputDir: "{{srcDir}}",
|
|
7
|
+
hidden: true,
|
|
8
|
+
render(symbolName, data) {
|
|
9
|
+
return `import { expect, describe, it } from "vitest";
|
|
10
|
+
import { ${symbolName} } from "./${data.symbolPathBasename}.js";
|
|
11
|
+
|
|
12
|
+
describe("${symbolName}", () => {
|
|
13
|
+
it("should do something", () => {
|
|
14
|
+
@${symbolName}({})
|
|
15
|
+
class Test {
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
expect(typeof ${symbolName}).toBe("function")
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
`;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
export default defineTemplate({
|
|
3
|
+
id: "decorator.endpoint.spec",
|
|
4
|
+
label: "Endpoint Decorator Test",
|
|
5
|
+
fileName: "{{symbolName}}.spec",
|
|
6
|
+
outputDir: "{{srcDir}}",
|
|
7
|
+
hidden: true,
|
|
8
|
+
render(symbolName, data) {
|
|
9
|
+
return `import { expect, describe, it } from "vitest";
|
|
10
|
+
import { Store } from "@tsed/core";
|
|
11
|
+
import { ${symbolName} } from "./${data.symbolPathBasename}.js";
|
|
12
|
+
|
|
13
|
+
describe("${symbolName}", () => {
|
|
14
|
+
it("should store options", () => {
|
|
15
|
+
class Test {
|
|
16
|
+
@${symbolName}({options: "options"})
|
|
17
|
+
method(param: string) {}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const store = Store.fromMethod(Test, "method");
|
|
21
|
+
|
|
22
|
+
expect(store.get(${symbolName})).toEqual({options: "options"});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
export default defineTemplate({
|
|
3
|
+
id: "decorator.method.spec",
|
|
4
|
+
label: "Method Decorator Test",
|
|
5
|
+
fileName: "{{symbolName}}.spec",
|
|
6
|
+
outputDir: "{{srcDir}}",
|
|
7
|
+
hidden: true,
|
|
8
|
+
render(symbolName, data) {
|
|
9
|
+
return `import { expect, describe, it } from "vitest";
|
|
10
|
+
import { ${symbolName} } from "./${data.symbolPathBasename}.js";
|
|
11
|
+
|
|
12
|
+
describe("${symbolName}", () => {
|
|
13
|
+
it("should do something", () => {
|
|
14
|
+
class Test {
|
|
15
|
+
@${symbolName}({})
|
|
16
|
+
method(){}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
expect(typeof ${symbolName}).toBe("function")
|
|
20
|
+
expect(typeof ${symbolName}()).toBe("function")
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
export default defineTemplate({
|
|
3
|
+
id: "decorator.param.spec",
|
|
4
|
+
label: "Parameter Decorator Test",
|
|
5
|
+
fileName: "{{symbolName}}.spec",
|
|
6
|
+
outputDir: "{{srcDir}}",
|
|
7
|
+
hidden: true,
|
|
8
|
+
render(symbolName, data) {
|
|
9
|
+
return `import { expect, describe, it } from "vitest";
|
|
10
|
+
import { Store } from "@tsed/core";
|
|
11
|
+
import { ${symbolName} } from "./${data.symbolPathBasename}.js";
|
|
12
|
+
|
|
13
|
+
describe("${symbolName}", () => {
|
|
14
|
+
it("should store options", () => {
|
|
15
|
+
class Test {
|
|
16
|
+
method(@${symbolName}({options: "options"}) param: string){}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const store = Store.from(Test, "method", 0)
|
|
20
|
+
|
|
21
|
+
expect(store.get(${symbolName})).toEqual({options: "options"});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
export default defineTemplate({
|
|
3
|
+
id: "decorator.parameter.spec",
|
|
4
|
+
label: "Parameters Decorator Test",
|
|
5
|
+
fileName: "{{symbolName}}.spec",
|
|
6
|
+
outputDir: "{{srcDir}}",
|
|
7
|
+
hidden: true,
|
|
8
|
+
render(symbolName, data) {
|
|
9
|
+
return `import { expect, describe, it } from "vitest";
|
|
10
|
+
import { ${symbolName} } from "./${data.symbolPathBasename}.js";
|
|
11
|
+
|
|
12
|
+
describe("${symbolName}", () => {
|
|
13
|
+
it("should do something", () => {
|
|
14
|
+
class Test {
|
|
15
|
+
method(@${symbolName}({}) param: string){}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
expect(typeof ${symbolName}).toBe("function")
|
|
19
|
+
expect(typeof ${symbolName}()).toBe("function")
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
`;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
export default defineTemplate({
|
|
3
|
+
id: "decorator.prop.spec",
|
|
4
|
+
label: "Property Decorator with @Property Test",
|
|
5
|
+
fileName: "{{symbolName}}.spec",
|
|
6
|
+
outputDir: "{{srcDir}}",
|
|
7
|
+
hidden: true,
|
|
8
|
+
render(symbolName, data) {
|
|
9
|
+
return `import { expect, describe, it } from "vitest";
|
|
10
|
+
import { Store } from "@tsed/core";
|
|
11
|
+
import { ${symbolName} } from "./${data.symbolPathBasename}.js";
|
|
12
|
+
|
|
13
|
+
describe("${symbolName}", () => {
|
|
14
|
+
it("should store options", () => {
|
|
15
|
+
class Test {
|
|
16
|
+
@${symbolName}({options: "options"})
|
|
17
|
+
property: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const store = Store.from(Test, "property");
|
|
21
|
+
|
|
22
|
+
expect(store.get(${symbolName})).toEqual({options: "options"});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
export default defineTemplate({
|
|
3
|
+
id: "decorator.property.spec",
|
|
4
|
+
label: "Property Decorator Test",
|
|
5
|
+
fileName: "{{symbolName}}.spec",
|
|
6
|
+
outputDir: "{{srcDir}}",
|
|
7
|
+
hidden: true,
|
|
8
|
+
render(symbolName, data) {
|
|
9
|
+
return `import { expect, describe, it } from "vitest";
|
|
10
|
+
import { ${symbolName} } from "./${data.symbolPathBasename}.js";
|
|
11
|
+
|
|
12
|
+
describe("${symbolName}", () => {
|
|
13
|
+
it("should do something", () => {
|
|
14
|
+
class Test {
|
|
15
|
+
@${symbolName}({})
|
|
16
|
+
property: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
expect(typeof ${symbolName}).toBe("function")
|
|
20
|
+
expect(typeof ${symbolName}()).toBe("function")
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
export default defineTemplate({
|
|
3
|
+
id: "generic.spec",
|
|
4
|
+
label: "Generic Spec",
|
|
5
|
+
fileName: "{{symbolName}}.spec",
|
|
6
|
+
outputDir: "{{srcDir}}",
|
|
7
|
+
hidden: true,
|
|
8
|
+
render(symbolName, data) {
|
|
9
|
+
return `import { expect, describe, it, beforeEach, afterEach } from "vitest";
|
|
10
|
+
import { PlatformTest, inject } from "@tsed/platform-http/testing";
|
|
11
|
+
import { ${symbolName} } from "./${data.symbolPathBasename}.js";
|
|
12
|
+
|
|
13
|
+
describe("${symbolName}", () => {
|
|
14
|
+
beforeEach(PlatformTest.create);
|
|
15
|
+
afterEach(PlatformTest.reset);
|
|
16
|
+
|
|
17
|
+
it("should do something", () => {
|
|
18
|
+
const instance = inject(${symbolName});
|
|
19
|
+
// const instance = PlatformTest.invoke<${symbolName}>(${symbolName}); // get fresh instance
|
|
20
|
+
|
|
21
|
+
expect(instance).toBeInstanceOf(${symbolName});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Import all templates to register them with the DI container
|
|
2
|
+
import "./generic.spec.template.js";
|
|
3
|
+
import "./controller.integration.template.js";
|
|
4
|
+
import "./server.integration.template.js";
|
|
5
|
+
import "./decorator.class.template.js";
|
|
6
|
+
import "./decorator.endpoint.template.js";
|
|
7
|
+
import "./decorator.method.template.js";
|
|
8
|
+
import "./decorator.param.template.js";
|
|
9
|
+
import "./decorator.parameter.template.js";
|
|
10
|
+
import "./decorator.prop.template.js";
|
|
11
|
+
import "./decorator.property.template.js";
|
|
12
|
+
import "./vitest.config.template.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
export default defineTemplate({
|
|
3
|
+
id: "server.integration",
|
|
4
|
+
label: "Server Integration Test",
|
|
5
|
+
outputDir: "{{srcDir}}",
|
|
6
|
+
hidden: true,
|
|
7
|
+
render(symbolName, data) {
|
|
8
|
+
return `import { expect, describe, it, beforeAll, afterAll } from "vitest";
|
|
9
|
+
import { PlatformTest } from "@tsed/platform-http/testing";
|
|
10
|
+
import SuperTest from "supertest";
|
|
11
|
+
import { ${symbolName} } from "./${data.symbolPathBasename}.js";
|
|
12
|
+
|
|
13
|
+
describe("${symbolName}", () => {
|
|
14
|
+
beforeAll(PlatformTest.bootstrap(${symbolName}));
|
|
15
|
+
afterAll(PlatformTest.reset);
|
|
16
|
+
|
|
17
|
+
it("should call GET ${data.route}", async () => {
|
|
18
|
+
const request = SuperTest(PlatformTest.callback());
|
|
19
|
+
const response = await request.get("${data.route}").expect(404);
|
|
20
|
+
|
|
21
|
+
expect(response.body).toEqual({
|
|
22
|
+
errors: [],
|
|
23
|
+
message: 'Resource "/rest" not found',
|
|
24
|
+
name: "NOT_FOUND",
|
|
25
|
+
status: 404,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
});
|
package/{templates/init/vitest.config.mts.hbs → lib/esm/templates/vitest.config.template.js}
RENAMED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { defineTemplate } from "@tsed/cli";
|
|
2
|
+
export default defineTemplate({
|
|
3
|
+
id: "vitest.config",
|
|
4
|
+
label: "Vitest configuration",
|
|
5
|
+
fileName: "vitest.config",
|
|
6
|
+
preserveCase: true,
|
|
7
|
+
outputDir: ".",
|
|
8
|
+
hidden: true,
|
|
9
|
+
render() {
|
|
10
|
+
return `import swc from "unplugin-swc";
|
|
2
11
|
import {defineConfig} from "vitest/config";
|
|
3
12
|
|
|
4
13
|
export default defineConfig({
|
|
@@ -9,7 +18,7 @@ export default defineConfig({
|
|
|
9
18
|
plugins: [
|
|
10
19
|
// This is required to build the test files with SWC
|
|
11
20
|
swc.vite({
|
|
12
|
-
// Explicitly set the module type to avoid inheriting this value from a
|
|
21
|
+
// Explicitly set the module type to avoid inheriting this value from a \`.swcrc\` config file
|
|
13
22
|
module: {type: "es6"},
|
|
14
23
|
jsc: {
|
|
15
24
|
transform: {
|
|
@@ -18,4 +27,6 @@ export default defineConfig({
|
|
|
18
27
|
}
|
|
19
28
|
})
|
|
20
29
|
]
|
|
30
|
+
});`;
|
|
31
|
+
}
|
|
21
32
|
});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
addDevDependencies(): void;
|
|
1
|
+
import "./templates/index.js";
|
|
2
|
+
import { type AlterGenerateTasks, type AlterInitSubTasks, type AlterPackageJson, type GenerateCmdContext, type InitCmdContext } from "@tsed/cli";
|
|
3
|
+
import { ProjectPackageJson, type Task, type Tasks } from "@tsed/cli-core";
|
|
4
|
+
export declare class CliPluginVitestModule implements AlterInitSubTasks, AlterPackageJson, AlterGenerateTasks {
|
|
5
|
+
$alterPackageJson(packageJson: ProjectPackageJson, data: InitCmdContext): ProjectPackageJson;
|
|
6
|
+
$alterInitSubTasks(tasks: Task[], data: InitCmdContext): Task[];
|
|
7
|
+
$alterGenerateTasks(tasks: Task[], data: GenerateCmdContext): Tasks;
|
|
9
8
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "./generic.spec.template.js";
|
|
2
|
+
import "./controller.integration.template.js";
|
|
3
|
+
import "./server.integration.template.js";
|
|
4
|
+
import "./decorator.class.template.js";
|
|
5
|
+
import "./decorator.endpoint.template.js";
|
|
6
|
+
import "./decorator.method.template.js";
|
|
7
|
+
import "./decorator.param.template.js";
|
|
8
|
+
import "./decorator.parameter.template.js";
|
|
9
|
+
import "./decorator.prop.template.js";
|
|
10
|
+
import "./decorator.property.template.js";
|
|
11
|
+
import "./vitest.config.template.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/cli-plugin-vitest",
|
|
3
3
|
"description": "Ts.ED CLI plugin. Add Jest support",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0-alpha.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/esm/index.js",
|
|
7
7
|
"source": "./src/index.ts",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@tsed/cli": "
|
|
26
|
-
"@tsed/cli-core": "
|
|
27
|
-
"@tsed/typescript": "
|
|
25
|
+
"@tsed/cli": "7.0.0-alpha.1",
|
|
26
|
+
"@tsed/cli-core": "7.0.0-alpha.1",
|
|
27
|
+
"@tsed/typescript": "7.0.0-alpha.1",
|
|
28
28
|
"cross-env": "7.0.3",
|
|
29
29
|
"typescript": "5.6.2",
|
|
30
30
|
"vitest": "3.2.4"
|
|
@@ -39,5 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://github.com/tsedio/tsed-cli/tree/master/packages/cli-plugin-vitest",
|
|
41
41
|
"author": "Romain Lenzotti",
|
|
42
|
-
"license": "MIT"
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"tag": "alpha"
|
|
45
|
+
}
|
|
43
46
|
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { SrcRendererService } from "@tsed/cli";
|
|
3
|
-
import { inject, Injectable, OnExec } from "@tsed/cli-core";
|
|
4
|
-
import { normalizePath } from "@tsed/normalize-path";
|
|
5
|
-
import { TEMPLATE_DIR } from "../utils/templateDir.js";
|
|
6
|
-
let VitestGenerateHook = class VitestGenerateHook {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.srcRenderService = inject(SrcRendererService);
|
|
9
|
-
}
|
|
10
|
-
onGenerateExec(ctx) {
|
|
11
|
-
const { symbolPath } = ctx;
|
|
12
|
-
const { specTemplate, integrationTemplate, relativeSrcPath } = this.mapOptions(ctx);
|
|
13
|
-
return [
|
|
14
|
-
{
|
|
15
|
-
title: `Generate ${ctx.type} spec file to '${symbolPath}.spec.ts'`,
|
|
16
|
-
enabled() {
|
|
17
|
-
return !(ctx.type === "server" || ctx.type.includes(":dataSource") || ctx.type.includes(":connection"));
|
|
18
|
-
},
|
|
19
|
-
task: () => this.srcRenderService.render(specTemplate, { ...ctx, relativeSrcPath }, {
|
|
20
|
-
output: `${symbolPath}.spec.ts`,
|
|
21
|
-
templateDir: TEMPLATE_DIR
|
|
22
|
-
})
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
title: `Generate ${ctx.type} integration file '${symbolPath}.integration.spec.ts'`,
|
|
26
|
-
enabled() {
|
|
27
|
-
return ["controller", "server"].includes(ctx.type);
|
|
28
|
-
},
|
|
29
|
-
task: () => this.srcRenderService.render(integrationTemplate, { ...ctx, relativeSrcPath }, {
|
|
30
|
-
output: `${symbolPath}.integration.spec.ts`,
|
|
31
|
-
templateDir: TEMPLATE_DIR
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
];
|
|
35
|
-
}
|
|
36
|
-
mapOptions(options) {
|
|
37
|
-
const type = [options.type, options.templateType].filter(Boolean).join(".");
|
|
38
|
-
const specTemplate = this.srcRenderService.templateExists(`generate/${type}.spec.hbs`, { templateDir: TEMPLATE_DIR })
|
|
39
|
-
? `generate/${type}.spec.hbs`
|
|
40
|
-
: "generate/generic.spec.hbs";
|
|
41
|
-
const integrationTemplate = this.srcRenderService.templateExists(`generate/${type}.integration.hbs`, { templateDir: TEMPLATE_DIR })
|
|
42
|
-
? `generate/${type}.integration.hbs`
|
|
43
|
-
: "generate/generic.integration.hbs";
|
|
44
|
-
return {
|
|
45
|
-
specTemplate,
|
|
46
|
-
integrationTemplate,
|
|
47
|
-
relativeSrcPath: normalizePath(this.srcRenderService.relativeFrom(`${options.symbolPath}.integration.spec.ts`))
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
__decorate([
|
|
52
|
-
OnExec("generate"),
|
|
53
|
-
__metadata("design:type", Function),
|
|
54
|
-
__metadata("design:paramtypes", [Object]),
|
|
55
|
-
__metadata("design:returntype", Array)
|
|
56
|
-
], VitestGenerateHook.prototype, "onGenerateExec", null);
|
|
57
|
-
VitestGenerateHook = __decorate([
|
|
58
|
-
Injectable()
|
|
59
|
-
], VitestGenerateHook);
|
|
60
|
-
export { VitestGenerateHook };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { RootRendererService } from "@tsed/cli";
|
|
3
|
-
import { inject, Injectable, OnExec, ProjectPackageJson } from "@tsed/cli-core";
|
|
4
|
-
import { TEMPLATE_DIR } from "../utils/templateDir.js";
|
|
5
|
-
let VitestInitHook = class VitestInitHook {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.packageJson = inject(ProjectPackageJson);
|
|
8
|
-
this.rootRenderer = inject(RootRendererService);
|
|
9
|
-
}
|
|
10
|
-
onInitExec() {
|
|
11
|
-
return [
|
|
12
|
-
{
|
|
13
|
-
title: "Generate files for vitest",
|
|
14
|
-
task: (ctx) => {
|
|
15
|
-
return this.rootRenderer.renderAll(["vitest.config.mts.hbs"], ctx, {
|
|
16
|
-
templateDir: `${TEMPLATE_DIR}/init`
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
];
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
__decorate([
|
|
24
|
-
OnExec("init"),
|
|
25
|
-
__metadata("design:type", Function),
|
|
26
|
-
__metadata("design:paramtypes", []),
|
|
27
|
-
__metadata("design:returntype", void 0)
|
|
28
|
-
], VitestInitHook.prototype, "onInitExec", null);
|
|
29
|
-
VitestInitHook = __decorate([
|
|
30
|
-
Injectable()
|
|
31
|
-
], VitestInitHook);
|
|
32
|
-
export { VitestInitHook };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type GenerateCmdContext, SrcRendererService } from "@tsed/cli";
|
|
2
|
-
import { type Tasks } from "@tsed/cli-core";
|
|
3
|
-
export declare class VitestGenerateHook {
|
|
4
|
-
protected srcRenderService: SrcRendererService;
|
|
5
|
-
onGenerateExec(ctx: GenerateCmdContext): Tasks;
|
|
6
|
-
private mapOptions;
|
|
7
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { RootRendererService } from "@tsed/cli";
|
|
2
|
-
import { ProjectPackageJson } from "@tsed/cli-core";
|
|
3
|
-
export declare class VitestInitHook {
|
|
4
|
-
protected packageJson: ProjectPackageJson;
|
|
5
|
-
protected rootRenderer: RootRendererService;
|
|
6
|
-
onInitExec(): {
|
|
7
|
-
title: string;
|
|
8
|
-
task: (ctx: any) => import("rxjs").Observable<unknown>;
|
|
9
|
-
}[];
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const TEMPLATE_DIR: string;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from "vitest";
|
|
2
|
-
import { {{symbolName}} } from "./{{symbolPathBasename}}.js";
|
|
3
|
-
|
|
4
|
-
describe("{{symbolName}}", () => {
|
|
5
|
-
it("should do something", () => {
|
|
6
|
-
@{{symbolName}}({})
|
|
7
|
-
class Test {
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
expect(typeof {{symbolName}}).toBe("function")
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from "vitest";
|
|
2
|
-
import { Store } from "@tsed/core";
|
|
3
|
-
import { {{symbolName}} } from "./{{symbolPathBasename}}.js";
|
|
4
|
-
|
|
5
|
-
describe("{{symbolName}}", () => {
|
|
6
|
-
it("should store options", () => {
|
|
7
|
-
class Test {
|
|
8
|
-
@{{symbolName}}({options: "options"})
|
|
9
|
-
method() param: string){}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const store = Store.fromMethod(Test, "method");
|
|
13
|
-
|
|
14
|
-
expect(store.get({{symbolName}})).toEqual({options: "options"});
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from "vitest";
|
|
2
|
-
import { {{symbolName}} } from "./{{symbolPathBasename}}.js";
|
|
3
|
-
|
|
4
|
-
describe("{{symbolName}}", () => {
|
|
5
|
-
it("should do something", () => {
|
|
6
|
-
class Test {
|
|
7
|
-
@{{symbolName}}({})
|
|
8
|
-
method(){}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
expect(typeof {{symbolName}}).toBe("function")
|
|
12
|
-
expect(typeof {{symbolName}}()).toBe("function")
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from "vitest";
|
|
2
|
-
import { Store } from "@tsed/core";
|
|
3
|
-
import { {{symbolName}} } from "./{{symbolPathBasename}}.js";
|
|
4
|
-
|
|
5
|
-
describe("{{symbolName}}", () => {
|
|
6
|
-
it("should store options", () => {
|
|
7
|
-
class Test {
|
|
8
|
-
method(@{{symbolName}}({options: "options"}) param: string){}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const store = Store.from(Test, "method", 0)
|
|
12
|
-
|
|
13
|
-
expect(store.get({{symbolName}})).toEqual({options: "options"});
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from "vitest";
|
|
2
|
-
import { {{symbolName}} } from "./{{symbolPathBasename}}.js";
|
|
3
|
-
|
|
4
|
-
describe("{{symbolName}}", () => {
|
|
5
|
-
it("should do something", () => {
|
|
6
|
-
class Test {
|
|
7
|
-
method(@{{symbolName}}({}) param: string){}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
expect(typeof {{symbolName}}).toBe("function")
|
|
11
|
-
expect(typeof {{symbolName}}()).toBe("function")
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from "vitest";
|
|
2
|
-
import { Store } from "@tsed/core";
|
|
3
|
-
import { {{symbolName}} } from "./{{symbolPathBasename}}.js";
|
|
4
|
-
|
|
5
|
-
describe("{{symbolName}}", () => {
|
|
6
|
-
it("should store options", () => {
|
|
7
|
-
class Test {
|
|
8
|
-
@{{symbolName}}({options: "options"})
|
|
9
|
-
property: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const store = Store.from(Test, "property");
|
|
13
|
-
|
|
14
|
-
expect(store.get({{symbolName}})).toEqual({options: "options"});
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from "vitest";
|
|
2
|
-
import { {{symbolName}} } from "./{{symbolPathBasename}}.js";
|
|
3
|
-
|
|
4
|
-
describe("{{symbolName}}", () => {
|
|
5
|
-
it("should do something", () => {
|
|
6
|
-
class Test {
|
|
7
|
-
@{{symbolName}}({})
|
|
8
|
-
property: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
expect(typeof {{symbolName}}).toBe("function")
|
|
12
|
-
expect(typeof {{symbolName}}()).toBe("function")
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it, afterAll, beforeAll } from "vitest";
|
|
2
|
-
import { PlatformTest } from "@tsed/platform-http/testing";
|
|
3
|
-
import SuperTest from "supertest";
|
|
4
|
-
import { {{symbolName}} } from "./{{symbolPathBasename}}.js";
|
|
5
|
-
import { Server } from "{{relativeSrcPath}}/Server.js";
|
|
6
|
-
|
|
7
|
-
describe("{{symbolName}}", () => {
|
|
8
|
-
beforeAll(PlatformTest.bootstrap(Server, {
|
|
9
|
-
mount: {
|
|
10
|
-
"/": [{{symbolName}}]
|
|
11
|
-
}
|
|
12
|
-
}));
|
|
13
|
-
afterAll(PlatformTest.reset);
|
|
14
|
-
|
|
15
|
-
it("should call GET {{route}}", async () => {
|
|
16
|
-
const request = SuperTest(PlatformTest.callback());
|
|
17
|
-
const response = await request.get("{{route}}").expect(200);
|
|
18
|
-
|
|
19
|
-
expect(response.text).toEqual("hello");
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { PlatformTest } from "@tsed/platform-http/testing";
|
|
3
|
-
import { {{symbolName}} } from "./{{symbolPathBasename}}.js";
|
|
4
|
-
|
|
5
|
-
describe("{{symbolName}}", () => {
|
|
6
|
-
beforeEach(PlatformTest.create);
|
|
7
|
-
afterEach(PlatformTest.reset);
|
|
8
|
-
|
|
9
|
-
it("should do something", () => {
|
|
10
|
-
const instance = PlatformTest.get<{{symbolName}}>({{symbolName}});
|
|
11
|
-
// const instance = PlatformTest.invoke<{{symbolName}}>({{symbolName}}); // get fresh instance
|
|
12
|
-
|
|
13
|
-
expect(instance).toBeInstanceOf({{symbolName}});
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it, beforeAll, afterAll } from "vitest";
|
|
2
|
-
import { PlatformTest } from "@tsed/platform-http/testing";
|
|
3
|
-
import SuperTest from "supertest";
|
|
4
|
-
import { {{symbolName}} } from "./{{symbolPathBasename}}.js";
|
|
5
|
-
|
|
6
|
-
describe("{{symbolName}}", () => {
|
|
7
|
-
beforeAll(PlatformTest.bootstrap({{symbolName}}));
|
|
8
|
-
afterAll(PlatformTest.reset);
|
|
9
|
-
|
|
10
|
-
it("should call GET {{route}}", async () => {
|
|
11
|
-
const request = SuperTest(PlatformTest.callback());
|
|
12
|
-
const response = await request.get("{{route}}").expect(404);
|
|
13
|
-
|
|
14
|
-
expect(response.body).toEqual({
|
|
15
|
-
errors: [],
|
|
16
|
-
message: 'Resource "/rest" not found',
|
|
17
|
-
name: "NOT_FOUND",
|
|
18
|
-
status: 404,
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|