@typespec/emitter-framework 0.9.0-dev.8 → 0.9.0-dev.9
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/src/testing/scenario-test/code-block-expectation.d.ts +33 -0
- package/dist/src/testing/scenario-test/code-block-expectation.d.ts.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.js +69 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.d.ts +2 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.d.ts.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.js +80 -0
- package/dist/src/testing/scenario-test/harness.d.ts +2 -2
- package/dist/src/testing/scenario-test/harness.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/harness.js +69 -158
- package/dist/src/testing/scenario-test/index.d.ts +0 -1
- package/dist/src/testing/scenario-test/index.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/index.js +1 -2
- package/dist/src/testing/scenario-test/snippet-extractor.d.ts +1 -1
- package/dist/src/testing/scenario-test/snippet-extractor.js +1 -1
- package/dist/test/testing/snippet-extractor-csharp.test.js +3 -3
- package/dist/test/testing/snippet-extractor-java.test.js +3 -3
- package/dist/test/testing/snippet-extractor-python.test.js +2 -2
- package/dist/test/testing/snippet-extractor-typescript.test.js +3 -3
- package/package.json +2 -3
- package/src/testing/scenario-test/code-block-expectation.test.ts +95 -0
- package/src/testing/scenario-test/code-block-expectation.ts +115 -0
- package/src/testing/scenario-test/harness.ts +91 -236
- package/src/testing/scenario-test/index.ts +0 -1
- package/src/testing/scenario-test/snippet-extractor.ts +1 -1
- package/test/testing/snippet-extractor-csharp.test.ts +3 -3
- package/test/testing/snippet-extractor-java.test.ts +3 -3
- package/test/testing/snippet-extractor-python.test.ts +2 -2
- package/test/testing/snippet-extractor-typescript.test.ts +3 -3
- package/dist/src/testing/scenario-test/test-host.d.ts +0 -8
- package/dist/src/testing/scenario-test/test-host.d.ts.map +0 -1
- package/dist/src/testing/scenario-test/test-host.js +0 -49
- package/src/testing/scenario-test/test-host.ts +0 -83
|
@@ -2,7 +2,7 @@ import { d } from "@alloy-js/core/testing";
|
|
|
2
2
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
3
|
import {
|
|
4
4
|
createJavaExtractorConfig,
|
|
5
|
-
|
|
5
|
+
createSnippetExtractor,
|
|
6
6
|
type SnippetExtractor,
|
|
7
7
|
} from "../../src/testing/index.js";
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ describe("Java Snippet Extractor", () => {
|
|
|
10
10
|
let extractor: SnippetExtractor;
|
|
11
11
|
|
|
12
12
|
beforeEach(async () => {
|
|
13
|
-
extractor =
|
|
13
|
+
extractor = createSnippetExtractor(await createJavaExtractorConfig());
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("should extract a class", () => {
|
|
@@ -67,7 +67,7 @@ describe("Java Snippet Extractor - Enums", () => {
|
|
|
67
67
|
let extractor: SnippetExtractor;
|
|
68
68
|
|
|
69
69
|
beforeEach(async () => {
|
|
70
|
-
extractor =
|
|
70
|
+
extractor = createSnippetExtractor(await createJavaExtractorConfig());
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it("should extract a basic enum", async () => {
|
|
@@ -2,7 +2,7 @@ import { d } from "@alloy-js/core/testing";
|
|
|
2
2
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
3
|
import {
|
|
4
4
|
createPythonExtractorConfig,
|
|
5
|
-
|
|
5
|
+
createSnippetExtractor,
|
|
6
6
|
type SnippetExtractor,
|
|
7
7
|
} from "../../src/testing/index.js";
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ describe("Python Snippet Extractor", () => {
|
|
|
10
10
|
let extractor: SnippetExtractor;
|
|
11
11
|
|
|
12
12
|
beforeEach(async () => {
|
|
13
|
-
extractor =
|
|
13
|
+
extractor = createSnippetExtractor(await createPythonExtractorConfig());
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("should extract a class", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { d } from "@alloy-js/core/testing";
|
|
2
2
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
createSnippetExtractor,
|
|
5
5
|
createTypeScriptExtractorConfig,
|
|
6
6
|
type SnippetExtractor,
|
|
7
7
|
} from "../../src/testing/index.js";
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
describe("TypeScript Snippet Extractor", () => {
|
|
10
10
|
let extractor: SnippetExtractor;
|
|
11
11
|
beforeEach(async () => {
|
|
12
|
-
extractor =
|
|
12
|
+
extractor = createSnippetExtractor(await createTypeScriptExtractorConfig());
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
it("should extract a class", async () => {
|
|
@@ -138,7 +138,7 @@ describe("TypeScript Snippet Extractor", () => {
|
|
|
138
138
|
describe("TypeScript Snippet Extractor - Enums", () => {
|
|
139
139
|
let extractor: SnippetExtractor;
|
|
140
140
|
beforeEach(async () => {
|
|
141
|
-
extractor =
|
|
141
|
+
extractor = createSnippetExtractor(await createTypeScriptExtractorConfig());
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
it("should extract a basic enum", async () => {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Diagnostic } from "@typespec/compiler";
|
|
2
|
-
import { type TypeSpecTestLibrary } from "@typespec/compiler/testing";
|
|
3
|
-
export interface EmittedFile {
|
|
4
|
-
path: string;
|
|
5
|
-
content: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function emitWithDiagnostics(testLibrary: TypeSpecTestLibrary, emitterOutputDir: string, code: string): Promise<[EmittedFile[], readonly Diagnostic[]]>;
|
|
8
|
-
//# sourceMappingURL=test-host.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenario-test/test-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAKL,KAAK,mBAAmB,EACzB,MAAM,4BAA4B,CAAC;AAKpC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AA4BD,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,mBAAmB,EAChC,gBAAgB,EAAE,MAAM,EACxB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,SAAS,UAAU,EAAE,CAAC,CAAC,CAOjD"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { createTestHost, createTestWrapper } from "@typespec/compiler/testing";
|
|
2
|
-
import { HttpTestLibrary } from "@typespec/http/testing";
|
|
3
|
-
import { RestTestLibrary } from "@typespec/rest/testing";
|
|
4
|
-
import { join, relative } from "path";
|
|
5
|
-
async function createEmitterTestRunner(testLibrary, options = {}) {
|
|
6
|
-
const libraries = options.testHostConfig?.libraries ?? [testLibrary, HttpTestLibrary, RestTestLibrary];
|
|
7
|
-
const host = await createTestHost({
|
|
8
|
-
libraries
|
|
9
|
-
});
|
|
10
|
-
return createTestWrapper(host, {
|
|
11
|
-
autoImports: options.autoImports ?? ["@typespec/http", "@typespec/rest"],
|
|
12
|
-
autoUsings: options.autoUsings ?? ["TypeSpec.Http", "TypeSpec.Rest"],
|
|
13
|
-
compilerOptions: options.compilerOptions ?? {
|
|
14
|
-
noEmit: false,
|
|
15
|
-
emit: [testLibrary.name]
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export async function emitWithDiagnostics(testLibrary, emitterOutputDir, code) {
|
|
20
|
-
const runner = await createEmitterTestRunner(testLibrary);
|
|
21
|
-
await runner.compileAndDiagnose(code, {
|
|
22
|
-
outputDir: "tsp-output"
|
|
23
|
-
});
|
|
24
|
-
const result = await readFilesRecursively(emitterOutputDir, emitterOutputDir, runner);
|
|
25
|
-
return [result, runner.program.diagnostics];
|
|
26
|
-
}
|
|
27
|
-
async function readFilesRecursively(currentDir, emitterOutputDir, runner) {
|
|
28
|
-
const entries = await runner.program.host.readDir(currentDir);
|
|
29
|
-
const result = [];
|
|
30
|
-
for (const entry of entries) {
|
|
31
|
-
const fullPath = join(currentDir, entry);
|
|
32
|
-
const stat = await runner.program.host.stat(fullPath);
|
|
33
|
-
if (stat.isDirectory()) {
|
|
34
|
-
// Recursively read files in the directory
|
|
35
|
-
const nestedFiles = await readFilesRecursively(fullPath, emitterOutputDir, runner);
|
|
36
|
-
result.push(...nestedFiles);
|
|
37
|
-
} else if (stat.isFile()) {
|
|
38
|
-
// Read the file
|
|
39
|
-
// Read the file and store it with a relative path
|
|
40
|
-
const relativePath = relative(emitterOutputDir, fullPath);
|
|
41
|
-
const fileContent = await runner.program.host.readFile(fullPath);
|
|
42
|
-
result.push({
|
|
43
|
-
path: relativePath,
|
|
44
|
-
content: fileContent.text
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { CompilerOptions, Diagnostic } from "@typespec/compiler";
|
|
2
|
-
import {
|
|
3
|
-
type BasicTestRunner,
|
|
4
|
-
createTestHost,
|
|
5
|
-
createTestWrapper,
|
|
6
|
-
type TestHostConfig,
|
|
7
|
-
type TypeSpecTestLibrary,
|
|
8
|
-
} from "@typespec/compiler/testing";
|
|
9
|
-
import { HttpTestLibrary } from "@typespec/http/testing";
|
|
10
|
-
import { RestTestLibrary } from "@typespec/rest/testing";
|
|
11
|
-
import { join, relative } from "path";
|
|
12
|
-
|
|
13
|
-
export interface EmittedFile {
|
|
14
|
-
path: string;
|
|
15
|
-
content: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function createEmitterTestRunner(
|
|
19
|
-
testLibrary: TypeSpecTestLibrary,
|
|
20
|
-
options: {
|
|
21
|
-
testHostConfig?: TestHostConfig;
|
|
22
|
-
autoImports?: string[];
|
|
23
|
-
autoUsings?: string[];
|
|
24
|
-
compilerOptions?: CompilerOptions;
|
|
25
|
-
} = {},
|
|
26
|
-
) {
|
|
27
|
-
const libraries = options.testHostConfig?.libraries ?? [
|
|
28
|
-
testLibrary,
|
|
29
|
-
HttpTestLibrary,
|
|
30
|
-
RestTestLibrary,
|
|
31
|
-
];
|
|
32
|
-
const host = await createTestHost({ libraries });
|
|
33
|
-
|
|
34
|
-
return createTestWrapper(host, {
|
|
35
|
-
autoImports: options.autoImports ?? ["@typespec/http", "@typespec/rest"],
|
|
36
|
-
autoUsings: options.autoUsings ?? ["TypeSpec.Http", "TypeSpec.Rest"],
|
|
37
|
-
compilerOptions: options.compilerOptions ?? {
|
|
38
|
-
noEmit: false,
|
|
39
|
-
emit: [testLibrary.name],
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function emitWithDiagnostics(
|
|
45
|
-
testLibrary: TypeSpecTestLibrary,
|
|
46
|
-
emitterOutputDir: string,
|
|
47
|
-
code: string,
|
|
48
|
-
): Promise<[EmittedFile[], readonly Diagnostic[]]> {
|
|
49
|
-
const runner = await createEmitterTestRunner(testLibrary);
|
|
50
|
-
await runner.compileAndDiagnose(code, {
|
|
51
|
-
outputDir: "tsp-output",
|
|
52
|
-
});
|
|
53
|
-
const result = await readFilesRecursively(emitterOutputDir, emitterOutputDir, runner);
|
|
54
|
-
return [result, runner.program.diagnostics];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function readFilesRecursively(
|
|
58
|
-
currentDir: string,
|
|
59
|
-
emitterOutputDir: string,
|
|
60
|
-
runner: BasicTestRunner,
|
|
61
|
-
): Promise<EmittedFile[]> {
|
|
62
|
-
const entries = await runner.program.host.readDir(currentDir);
|
|
63
|
-
const result: EmittedFile[] = [];
|
|
64
|
-
|
|
65
|
-
for (const entry of entries) {
|
|
66
|
-
const fullPath = join(currentDir, entry);
|
|
67
|
-
const stat = await runner.program.host.stat(fullPath);
|
|
68
|
-
|
|
69
|
-
if (stat.isDirectory()) {
|
|
70
|
-
// Recursively read files in the directory
|
|
71
|
-
const nestedFiles = await readFilesRecursively(fullPath, emitterOutputDir, runner);
|
|
72
|
-
result.push(...nestedFiles);
|
|
73
|
-
} else if (stat.isFile()) {
|
|
74
|
-
// Read the file
|
|
75
|
-
// Read the file and store it with a relative path
|
|
76
|
-
const relativePath = relative(emitterOutputDir, fullPath);
|
|
77
|
-
const fileContent = await runner.program.host.readFile(fullPath);
|
|
78
|
-
result.push({ path: relativePath, content: fileContent.text });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return result;
|
|
83
|
-
}
|