Skip to content

Commit c1f62db

Browse files
test: consolidate tsconfig path edge coverage
1 parent 4e08174 commit c1f62db

1 file changed

Lines changed: 12 additions & 34 deletions

File tree

‎tests/specs/tsconfig.ts‎

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -177,54 +177,29 @@ export const tsconfig = ({ tsx }: NodeApis) => describe('tsconfig', () => {
177177
expect(pTsconfig.stdout).toBe('resolved via configDir');
178178
});
179179

180-
test('tsconfig paths can match colon aliases', async () => {
180+
test('tsconfig paths handle colon aliases and data URLs', async () => {
181181
await using fixture = await createFixture({
182182
'package.json': createPackageJson(packageType ? { type: packageType } : {}),
183183
'tsconfig.json': createTsconfig({
184184
compilerOptions: {
185185
baseUrl: '.',
186186
paths: {
187+
'data:*': ['./src/wrong.mjs'],
187188
'ns:*': ['./src/*'],
188189
},
189190
},
190191
}),
191192
'index.mts': `
192-
import { value } from 'ns:utils.mjs';
193+
import { value as colonAlias } from 'ns:utils.mjs';
194+
import { value as dataUrl } from 'data:text/javascript,export%20const%20value%20%3D%20%22data-url%22%3B';
193195
194-
console.log(value);
196+
console.log(JSON.stringify({
197+
colonAlias,
198+
dataUrl,
199+
}));
195200
`,
196201
src: {
197202
'utils.mts': "export const value = 'success';",
198-
},
199-
});
200-
201-
const pTsconfig = await tsx(['index.mts'], fixture.path);
202-
onTestFail((error) => {
203-
console.error(error);
204-
console.log(pTsconfig);
205-
});
206-
expect(pTsconfig.failed).toBe(false);
207-
expect(pTsconfig.stderr).toBe('');
208-
expect(pTsconfig.stdout).toBe('success');
209-
});
210-
211-
test('tsconfig paths do not resolve data URLs', async () => {
212-
await using fixture = await createFixture({
213-
'package.json': createPackageJson(packageType ? { type: packageType } : {}),
214-
'tsconfig.json': createTsconfig({
215-
compilerOptions: {
216-
baseUrl: '.',
217-
paths: {
218-
'data:*': ['./src/wrong.mjs'],
219-
},
220-
},
221-
}),
222-
'index.mts': `
223-
import { value } from 'data:text/javascript,export%20const%20value%20%3D%20%22data-url%22%3B';
224-
225-
console.log(value);
226-
`,
227-
src: {
228203
'wrong.mts': "export const value = 'wrong';",
229204
},
230205
});
@@ -236,7 +211,10 @@ export const tsconfig = ({ tsx }: NodeApis) => describe('tsconfig', () => {
236211
});
237212
expect(pTsconfig.failed).toBe(false);
238213
expect(pTsconfig.stderr).toBe('');
239-
expect(pTsconfig.stdout).toBe('data-url');
214+
expect(JSON.parse(pTsconfig.stdout)).toEqual({
215+
colonAlias: 'success',
216+
dataUrl: 'data-url',
217+
});
240218
});
241219
});
242220

0 commit comments

Comments
 (0)