From d1ec874daef3760e187645b2e0b8d26f82980538 Mon Sep 17 00:00:00 2001 From: Abdulaziz Ghuloum Date: Mon, 30 Dec 2024 05:27:06 +0300 Subject: [PATCH] got vitest to accept and run tests defined in rts files --- src/library-manager.ts | 16 +++++- test-project/.rts/test1.test.rts.json | 82 +++++++++++++++++++++++++++ test-project/.rts/test1.test.rts.ts | 4 ++ test-project/test1.test.rts | 7 +++ test-project/test1.test.rts.ts | 2 + tsconfig.tsbuildinfo | 2 +- vitest.config.ts | 1 + 7 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 test-project/.rts/test1.test.rts.json create mode 100644 test-project/.rts/test1.test.rts.ts create mode 100644 test-project/test1.test.rts create mode 100644 test-project/test1.test.rts.ts diff --git a/src/library-manager.ts b/src/library-manager.ts index c320e33..e1daf43 100644 --- a/src/library-manager.ts +++ b/src/library-manager.ts @@ -268,6 +268,9 @@ abstract class Module implements imported_module { cuid: this.state.cid, clauses: binding.clauses, }; + case "imported_type": + case "imported_lexical": + return binding; default: throw new Error(`unhandled binding type ${binding.type} for label '${name}'`); } @@ -468,9 +471,20 @@ class DtsModule extends Module { return [name, res]; } case "imported": { + const label = `e.${binding.name}.${binding.module}`; + //assert(binding.name !== undefined, `namespace reexports not handled yet`); + if (binding.name) { + context[label] = { + type: "imported_lexical", + cuid: binding.module, + name: binding.name, + }; + } else { + console.error(`nameless reexports not handled yet`); + } const res: import_resolution = { type: "ts", - label: { cuid: cid, name: `e.${binding.name}.${binding.module}` }, + label: { cuid: cid, name: label }, }; return [name, [res]]; } diff --git a/test-project/.rts/test1.test.rts.json b/test-project/.rts/test1.test.rts.json new file mode 100644 index 0000000..5ecdb0a --- /dev/null +++ b/test-project/.rts/test1.test.rts.json @@ -0,0 +1,82 @@ +{ + "cid": "test-project/test1.test.rts rewrite-ts-visualized 0.0.0", + "cookie": "rewrite-ts-016", + "imports": [ + { + "pkg": {"name": "vitest", "version": "2.1.8"}, + "pkg_relative_path": "./dist/index.d.ts" + } + ], + "exported_identifiers": {}, + "context": {}, + "unit": { + "cu_id": "test-project/test1.test.rts rewrite-ts-visualized 0.0.0", + "store": { + "r0": { + "type": "rib", + "normal_env": { + "suite": [ + [ + [ + "test-project/test1.test.rts rewrite-ts-visualized 0.0.0", + ["top", null] + ], + { + "cuid": "dist/index.d.ts vitest 2.1.8", + "name": "e.suite.@vitest/runner" + } + ] + ], + "test": [ + [ + [ + "test-project/test1.test.rts rewrite-ts-visualized 0.0.0", + ["top", null] + ], + { + "cuid": "dist/index.d.ts vitest 2.1.8", + "name": "e.test.@vitest/runner" + } + ] + ], + "expect": [ + [ + [ + "test-project/test1.test.rts rewrite-ts-visualized 0.0.0", + ["top", null] + ], + {"cuid": "dist/index.d.ts vitest 2.1.8", "name": "l.globalExpect"} + ] + ] + }, + "types_env": { + "suite": [ + [ + [ + "test-project/test1.test.rts rewrite-ts-visualized 0.0.0", + ["top", null] + ], + { + "cuid": "dist/index.d.ts vitest 2.1.8", + "name": "e.suite.@vitest/runner" + } + ] + ], + "test": [ + [ + [ + "test-project/test1.test.rts rewrite-ts-visualized 0.0.0", + ["top", null] + ], + { + "cuid": "dist/index.d.ts vitest 2.1.8", + "name": "e.test.@vitest/runner" + } + ] + ] + }, + "libs": ["es2024.full"] + } + } + } +} \ No newline at end of file diff --git a/test-project/.rts/test1.test.rts.ts b/test-project/.rts/test1.test.rts.ts new file mode 100644 index 0000000..f29c883 --- /dev/null +++ b/test-project/.rts/test1.test.rts.ts @@ -0,0 +1,4 @@ +import { suite as suite_1, test as test_2 } from "vitest"; +suite_1("sample test", () => { + test_2("should work", () => {}); +}); diff --git a/test-project/test1.test.rts b/test-project/test1.test.rts new file mode 100644 index 0000000..44da718 --- /dev/null +++ b/test-project/test1.test.rts @@ -0,0 +1,7 @@ +import { expect, test, suite } from "vitest"; + +suite("sample test", () => { + test("should work", () => { + + }); +}); diff --git a/test-project/test1.test.rts.ts b/test-project/test1.test.rts.ts new file mode 100644 index 0000000..37cfbd3 --- /dev/null +++ b/test-project/test1.test.rts.ts @@ -0,0 +1,2 @@ +/* This is an automatically generated file. Do not edit. */ +import { } from "./.rts/test1.test.rts.ts"; diff --git a/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo index d6c3b2a..a4be90d 100644 --- a/tsconfig.tsbuildinfo +++ b/tsconfig.tsbuildinfo @@ -1 +1 @@ -{"root":["./files.test.ts","./generate-stdlibs.test.ts","./vite.config.ts","./vitest.config.ts","./rtsc/compile-all.ts","./rtsc/watch.ts","./src/assert.ts","./src/ast.ts","./src/data.ts","./src/expander.ts","./src/fs-helpers.ts","./src/generate-stdlibs.ts","./src/generated-stdlibs.ts","./src/global-module.ts","./src/library-manager.ts","./src/llhelpers.ts","./src/parse-dts.ts","./src/parse.ts","./src/pprint.ts","./src/preexpand-handlers.ts","./src/preexpand-helpers.ts","./src/proxy-code.ts","./src/serialize.ts","./src/stx-error.ts","./src/stx.ts","./src/syntax-core-patterns.ts","./src/syntax-structures.ts","./src/tags.ts","./src/zipper.ts","./test-project/index.ts","./test-project/main.rts.ts","./test-project/mod.rts.ts","./ui/astvis.tsx","./ui/app.tsx","./ui/editor.tsx","./ui/main.tsx","./ui/vite-env.d.ts"],"version":"5.7.2"} \ No newline at end of file +{"root":["./files.test.ts","./generate-stdlibs.test.ts","./vite.config.ts","./vitest.config.ts","./rtsc/compile-all.ts","./rtsc/watch.ts","./src/assert.ts","./src/ast.ts","./src/data.ts","./src/expander.ts","./src/fs-helpers.ts","./src/generate-stdlibs.ts","./src/generated-stdlibs.ts","./src/global-module.ts","./src/library-manager.ts","./src/llhelpers.ts","./src/parse-dts.ts","./src/parse.ts","./src/pprint.ts","./src/preexpand-handlers.ts","./src/preexpand-helpers.ts","./src/proxy-code.ts","./src/serialize.ts","./src/stx-error.ts","./src/stx.ts","./src/syntax-core-patterns.ts","./src/syntax-structures.ts","./src/tags.ts","./src/zipper.ts","./test-project/index.ts","./test-project/main.rts.ts","./test-project/mod.rts.ts","./test-project/test1.test.rts.ts","./ui/astvis.tsx","./ui/app.tsx","./ui/editor.tsx","./ui/main.tsx","./ui/vite-env.d.ts"],"version":"5.7.2"} \ No newline at end of file diff --git a/vitest.config.ts b/vitest.config.ts index 7a85808..0aedeb2 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -3,6 +3,7 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { + include: ["**/*.test.ts", "**/.rts/*.test.rts.ts"], coverage: { provider: "v8", // or 'istanbul' },