-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { resolve } from 'path' | ||
import t from 'tap' | ||
// import { fileURLToPath } from 'url' | ||
// import { getLanguageService } from '../../src/service/language-service.js' | ||
// import { markFileNameInternal } from '../../src/service/resolve-module-name-literals.js' | ||
// | ||
// const svc = getLanguageService() | ||
// svc.getProgram() | ||
// | ||
// markFileNameInternal(fileURLToPath(import.meta.url)) | ||
|
||
t.test('commonjs program', async t => { | ||
const dir = t.testdir({ | ||
'tsconfig.json': JSON.stringify({ | ||
include: ['index.ts'], | ||
compilerOptions: { | ||
esModuleInterop: true, | ||
forceConsistentCasingInFileNames: true, | ||
module: 'commonjs', | ||
moduleResolution: 'node10', | ||
skipLibCheck: true, | ||
strict: true, | ||
target: 'es2022', | ||
}, | ||
}), | ||
'package.json': JSON.stringify({ type: 'commonjs' }), | ||
'index.ts': ` | ||
import assert from 'node:assert' | ||
import './def' | ||
import { bar } from './bar' | ||
import { baz } from './baz' | ||
import t from 'tap' | ||
assert.equal(1, 1) | ||
export type Foo = { | ||
foo: string | ||
} | ||
export const foo = (f: Foo) => f.foo | ||
`, | ||
'bar.cts': ` | ||
export const bar = 'bar' | ||
`, | ||
'baz.ts': ` | ||
export const baz = 'baz' | ||
`, | ||
}) | ||
const cwd = process.cwd() | ||
process.chdir(dir) | ||
t.teardown(() => process.chdir(cwd)) | ||
const { getLanguageService } = (await t.mockImport( | ||
'../../src/service/language-service.js' | ||
)) as typeof import('../../src/service/language-service.js') | ||
const { markFileNameInternal } = (await t.mockImport( | ||
'../../src/service/resolve-module-name-literals.js' | ||
)) as typeof import('../../src/service/resolve-module-name-literals.js') | ||
const svc = getLanguageService() | ||
svc.getHost().resolveModuleNameLiterals | ||
svc.getProgram() | ||
markFileNameInternal(resolve(dir, 'index.ts')) | ||
}) | ||
|
||
t.test('esm program', async t => { | ||
const dir = t.testdir({ | ||
'tsconfig.json': JSON.stringify({ | ||
include: ['index.ts'], | ||
compilerOptions: { | ||
esModuleInterop: true, | ||
forceConsistentCasingInFileNames: true, | ||
module: 'nodenext', | ||
moduleResolution: 'nodenext', | ||
skipLibCheck: true, | ||
strict: true, | ||
target: 'es2022', | ||
}, | ||
}), | ||
'package.json': JSON.stringify({ type: 'module' }), | ||
'index.ts': ` | ||
import assert from 'node:assert' | ||
import { bar } from './bar.cjs' | ||
import { baz } from './baz.js' | ||
import t from 'tap' | ||
assert.equal(1, 1) | ||
export type Foo = { | ||
foo: string | ||
} | ||
export const foo = (f: Foo) => f.foo | ||
`, | ||
'bar.cts': ` | ||
export const bar = 'bar' | ||
`, | ||
'baz.ts': ` | ||
export const baz = 'baz' | ||
`, | ||
}) | ||
const cwd = process.cwd() | ||
process.chdir(dir) | ||
t.teardown(() => process.chdir(cwd)) | ||
const { getLanguageService } = (await t.mockImport( | ||
'../../src/service/language-service.js' | ||
)) as typeof import('../../src/service/language-service.js') | ||
const { markFileNameInternal } = (await t.mockImport( | ||
'../../src/service/resolve-module-name-literals.js' | ||
)) as typeof import('../../src/service/resolve-module-name-literals.js') | ||
const svc = getLanguageService() | ||
svc.getHost().resolveModuleNameLiterals | ||
svc.getProgram() | ||
markFileNameInternal(resolve(dir, 'index.ts')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import t from 'tap' | ||
import { getLanguageService } from '../../src/service/language-service.js' | ||
|
||
getLanguageService().getProgram() | ||
t.pass('just a test file for coverage purposes, nothing to do') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters