From 8baac646bb902976ef0f561d3a2750aa82f4c980 Mon Sep 17 00:00:00 2001 From: "Alexander J. Vincent" Date: Sat, 22 Jun 2024 13:01:42 -0700 Subject: [PATCH] test with subpath import --- test/bin.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/bin.ts b/test/bin.ts index bcbd91e..bb86e1e 100644 --- a/test/bin.ts +++ b/test/bin.ts @@ -62,6 +62,33 @@ t.test('actually run a program', async t => { export const f: Foo = { bar: true, baz: 'xyz' } console.error(f) `, + + // subpath import tests + 'package.json': JSON.stringify({ + "type": "module", + "imports": { + "#utilities/*": "./utilities/*" + } + }), + 'tsconfig.json': JSON.stringify({ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "#utilities/*": ["./utilities/*"], + } + }, + }), + + 'utilities': { + 'source': { + 'constants.ts': 'enum Constants { one = "one", two = "two" }; export default Constants;' + } + }, + + "test": { + 'getOne.ts': `import Constants from "../utilities/source/constants.js"; console.log(Constants.one);`, + 'getTwo.ts': `import Constants from "#utilities/source/constants.js"; console.log(Constants.two);` + } }) const rel = relative(process.cwd(), dir).replace(/\\/g, '/') @@ -122,4 +149,20 @@ t.test('actually run a program', async t => { t.equal(status, 0) t.equal(stdout, 'ok\n') }) + + t.test('run file with subpath imports', async t => { + { + const pathToFile = `./${rel}/test/getOne.ts` + const { stdout, status } = run([pathToFile]) + t.equal(status, 0) + t.equal(stdout, 'one\n') + } + + { + const pathToFile = `./${rel}/test/getTwo.ts` + const { stdout, status } = run([pathToFile]) + t.equal(status, 0) + t.equal(stdout, 'two\n') + } + }) })