fix tsconfig + remove forgotten duplicated test (#4886)

This commit is contained in:
Kevin Marrec 2019-01-29 20:19:21 +01:00 committed by Pooya Parsa
parent 445d50c250
commit 774823ba41
4 changed files with 9 additions and 48 deletions

View File

@ -44,6 +44,9 @@ export async function setup(tsConfigPath) {
} }
// https://github.com/TypeStrong/ts-node // https://github.com/TypeStrong/ts-node
register({ register({
project: tsConfigPath project: tsConfigPath,
compilerOptions: {
module: 'commonjs'
}
}) })
} }

View File

@ -35,7 +35,10 @@ describe('typescript setup', () => {
expect(register).toHaveBeenCalledTimes(1) expect(register).toHaveBeenCalledTimes(1)
expect(register).toHaveBeenCalledWith({ expect(register).toHaveBeenCalledWith({
project: tsConfigPath project: tsConfigPath,
compilerOptions: {
module: 'commonjs'
}
}) })
}) })

View File

@ -1,6 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "esnext", "target": "esnext",
"module": "esnext",
"moduleResolution": "node", "moduleResolution": "node",
"lib": [ "lib": [
"esnext", "esnext",

View File

@ -1,46 +0,0 @@
import { resolve } from 'path'
import { exists, mkdirp, readJSON, remove } from 'fs-extra'
import { register } from 'ts-node'
import { setup as setupTypeScript } from '@nuxt/typescript'
jest.mock('ts-node')
describe('typescript setup', () => {
const rootDir = 'tmp'
const tsConfigPath = resolve(rootDir, 'tsconfig.json')
beforeAll(async () => {
// We're assuming that rootDir provided to setupTypeScript is existing so we create the tested one
await mkdirp(rootDir)
await setupTypeScript(tsConfigPath)
})
test('tsconfig.json has been generated if missing', async () => {
expect(await exists(tsConfigPath)).toBe(true)
expect(await readJSON(tsConfigPath)).toEqual({
extends: '@nuxt/typescript',
compilerOptions: {
baseUrl: '.',
types: [
'@types/node',
'@nuxt/vue-app'
]
}
})
})
test('ts-node has been registered once', async () => {
// Call setupTypeScript a second time to test guard
await setupTypeScript(tsConfigPath)
expect(register).toHaveBeenCalledTimes(1)
expect(register).toHaveBeenCalledWith({
project: tsConfigPath
})
})
afterAll(async () => {
// Clean workspace by removing the temporary folder (and the generated tsconfig.json at the same time)
await remove(tsConfigPath)
})
})