Skip to content

Commit

Permalink
tests: Add test matrix for ignored() to ensure only specific extensio…
Browse files Browse the repository at this point in the history
…ns are sent to TypeScript compiler
  • Loading branch information
Concision committed Aug 11, 2020
1 parent ce5f663 commit de289f6
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,38 @@ describe('ts-node', function () {
it('should create generic compiler instances', () => {
const service = create({ compilerOptions: { target: 'es5' }, skipProject: true })
const output = service.compile('const x = 10', 'test.ts')

expect(output).to.contain('var x = 10;')
})
})

describe('issue #1098', () => {
function testIgnored (ignored: tsNodeTypes.Register['ignored'], allowed: string[], disallowed: string[]) {
for (const ext of allowed) {
expect(ignored(join(__dirname, `index${ext}`))).equal(false, `should accept ${ext} files`)
}
for (const ext of disallowed) {
expect(ignored(join(__dirname, `index${ext}`))).equal(true, `should ignore ${ext} files`)
}
}

it('correctly filters file extensions from the compiler when allowJs=false and jsx=false', () => {
const { ignored } = create({ compilerOptions: { }, skipProject: true })
testIgnored(ignored, ['.ts'], ['.js', '.tsx', '.jsx', '.mjs', '.cjs', '.xyz', ''])
})
it('correctly filters file extensions from the compiler when allowJs=true and jsx=false', () => {
const { ignored } = create({ compilerOptions: { allowJs: true }, skipProject: true })
testIgnored(ignored, ['.ts', '.js'], ['.tsx', '.jsx', '.mjs', '.cjs', '.xyz', ''])
})
it('correctly filters file extensions from the compiler when allowJs=false and jsx=true', () => {
const { ignored } = create({ compilerOptions: { allowJs: false, jsx: 'preserve' }, skipProject: true })
testIgnored(ignored, ['.ts', '.tsx'], ['.js', '.jsx', '.mjs', '.cjs', '.xyz', ''])
})
it('correctly filters file extensions from the compiler when allowJs=true and jsx=true', () => {
const { ignored } = create({ compilerOptions: { allowJs: true, jsx: 'preserve' }, skipProject: true })
testIgnored(ignored, ['.ts', '.tsx', '.js', '.jsx'], ['.mjs', '.cjs', '.xyz', ''])
})
})

describe('esm', () => {
this.slow(1000)

Expand Down

0 comments on commit de289f6

Please sign in to comment.