Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luciorubeens committed Nov 25, 2019
1 parent 479838c commit 75ccd2d
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 56 deletions.
1 change: 1 addition & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export default async function getBaseWebpackConfig(
new TsConfigPathsPlugin({
configFile: useTypeScript ? tsConfigPath : jsConfigPath,
extensions: resolveExtensions,
silent: true,
}),
]
: []),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@/components/*": ["components/*"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { HELLO } from '../constants/config'
export default () => <h1>{HELLO}</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.HELLO = 'Hello TypeScript'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Hello from '@/components/Hello'

export default () => <Hello />
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { HELLO } from 'constants/config'

export default () => <h1>{HELLO}</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { HELLO } from '../constants/config'
export default () => <h1>{HELLO}</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const HELLO = 'Hello TypeScript'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Hello from '@/components/Hello'

export default () => <Hello />
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { HELLO } from 'constants/config'

export default () => <h1>{HELLO}</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@/components/*": ["components/*"]
},
"jsx": "preserve",
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}
161 changes: 108 additions & 53 deletions test/integration/tsconfig-verifier/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,78 +14,133 @@ import { launchApp, findPort, killApp, renderViaHTTP } from 'next-test-utils'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5

describe('Fork ts checker plugin', () => {
const appDir = path.join(__dirname, '../')
const tsConfig = path.join(appDir, 'tsconfig.json')
let appPort
let app

beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
describe('Config File Verifier', () => {
describe('Fork ts checker plugin', () => {
const appDir = path.join(__dirname, '../fixtures/blank')
const tsConfig = path.join(appDir, 'tsconfig.json')

afterAll(async () => {
await killApp(app)
await remove(tsConfig)
})
let appPort
let app

it('Creates a default tsconfig.json when one is missing', async () => {
expect(await exists(tsConfig)).toBe(true)
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})

const tsConfigContent = await readFile(tsConfig)
let parsedTsConfig
expect(() => {
parsedTsConfig = JSON.parse(tsConfigContent)
}).not.toThrow()
afterAll(async () => {
await killApp(app)
await remove(tsConfig)
})

expect(parsedTsConfig.exclude[0]).toBe('node_modules')
})
it('Creates a default tsconfig.json when one is missing', async () => {
expect(await exists(tsConfig)).toBe(true)

const tsConfigContent = await readFile(tsConfig)
let parsedTsConfig
expect(() => {
parsedTsConfig = JSON.parse(tsConfigContent)
}).not.toThrow()

expect(parsedTsConfig.exclude[0]).toBe('node_modules')
})

it('Works with an empty tsconfig.json (docs)', async () => {
await killApp(app)

await remove(tsConfig)
await new Promise(resolve => setTimeout(resolve, 500))

expect(await exists(tsConfig)).toBe(false)

await createFile(tsConfig)
await new Promise(resolve => setTimeout(resolve, 500))

it('Works with an empty tsconfig.json (docs)', async () => {
await killApp(app)
expect(await readFile(tsConfig, 'utf8')).toBe('')

await remove(tsConfig)
await new Promise(resolve => setTimeout(resolve, 500))
await killApp(app)
await new Promise(resolve => setTimeout(resolve, 500))

expect(await exists(tsConfig)).toBe(false)
appPort = await findPort()
app = await launchApp(appDir, appPort)

await createFile(tsConfig)
await new Promise(resolve => setTimeout(resolve, 500))
const tsConfigContent = await readFile(tsConfig)
let parsedTsConfig
expect(() => {
parsedTsConfig = JSON.parse(tsConfigContent)
}).not.toThrow()

expect(await readFile(tsConfig, 'utf8')).toBe('')
expect(parsedTsConfig.exclude[0]).toBe('node_modules')
})

await killApp(app)
await new Promise(resolve => setTimeout(resolve, 500))
it('Updates an existing tsconfig.json with required value', async () => {
await killApp(app)

appPort = await findPort()
app = await launchApp(appDir, appPort)
let parsedTsConfig = await readJSON(tsConfig)
parsedTsConfig.compilerOptions.esModuleInterop = false

const tsConfigContent = await readFile(tsConfig)
let parsedTsConfig
expect(() => {
parsedTsConfig = JSON.parse(tsConfigContent)
}).not.toThrow()
await writeJSON(tsConfig, parsedTsConfig)
appPort = await findPort()
app = await launchApp(appDir, appPort)

expect(parsedTsConfig.exclude[0]).toBe('node_modules')
parsedTsConfig = await readJSON(tsConfig)
expect(parsedTsConfig.compilerOptions.esModuleInterop).toBe(true)
})

it('Renders a TypeScript page correctly', async () => {
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello TypeScript/)
})
})

it('Updates an existing tsconfig.json with required value', async () => {
await killApp(app)
describe('Parse TypeScript Config', () => {
const appDir = path.join(__dirname, '../fixtures/typescript-base-url')

let appPort
let app

let parsedTsConfig = await readJSON(tsConfig)
parsedTsConfig.compilerOptions.esModuleInterop = false
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})

await writeJSON(tsConfig, parsedTsConfig)
appPort = await findPort()
app = await launchApp(appDir, appPort)
afterAll(async () => {
await killApp(app)
})

parsedTsConfig = await readJSON(tsConfig)
expect(parsedTsConfig.compilerOptions.esModuleInterop).toBe(true)
it('Works with a custom baseURL', async () => {
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello TypeScript/)
})

it('Works with a custom path', async () => {
const html = await renderViaHTTP(appPort, '/hello')
expect(html).toMatch(/Hello TypeScript/)
})
})

it('Renders a TypeScript page correctly', async () => {
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello TypeScript/)
describe('Parse JS Config', () => {
const appDir = path.join(__dirname, '../fixtures/jsconfig-base-url')

let appPort
let app

beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})

afterAll(async () => {
await killApp(app)
})

it('Works with a custom baseURL', async () => {
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello TypeScript/)
})

it('Works with a custom path', async () => {
const html = await renderViaHTTP(appPort, '/hello')
expect(html).toMatch(/Hello TypeScript/)
})
})
})
47 changes: 44 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,11 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==

"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=

"@types/loader-utils@1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@types/loader-utils/-/loader-utils-1.1.3.tgz#82b9163f2ead596c68a8c03e450fbd6e089df401"
Expand Down Expand Up @@ -4396,9 +4401,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000980, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001002, caniuse-lite@^1.0.30001010:
version "1.0.30001011"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001011.tgz#0d6c4549c78c4a800bb043a83ca0cbe0aee6c6e1"
integrity sha512-h+Eqyn/YA6o6ZTqpS86PyRmNWOs1r54EBDcd2NTwwfsXQ8re1B38SnB+p2RKF8OUsyEIjeDU8XGec1RGO/wYCg==
version "1.0.30001012"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001012.tgz#653ec635e815b9e0fb801890923b0c2079eb34ec"
integrity sha512-7RR4Uh04t9K1uYRWzOJmzplgEOAXbfK72oVNokCdMzA67trrhPzy93ahKk1AWHiA0c58tD2P+NHqxrA8FZ+Trg==

capitalize@1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -6121,6 +6126,15 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.1:
dependencies:
once "^1.4.0"

enhanced-resolve@^4.0.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.1.1.tgz#2937e2b8066cd0fe7ce0990a98f0d71a35189f66"
integrity sha512-98p2zE+rL7/g/DzMHMTF4zZlCgeVdJ7yr6xzEpJRYwFYrGi9ANdn5DnJURg6RpBkyk60XYDnWIv51VfIhfNGuA==
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.5.0"
tapable "^1.0.0"

enhanced-resolve@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.1.0.tgz#41c7e0bfdfe74ac1ffe1e57ad6a5c6c9f3742a7f"
Expand Down Expand Up @@ -10114,6 +10128,14 @@ memory-fs@^0.4.0, memory-fs@^0.4.1:
errno "^0.1.3"
readable-stream "^2.0.1"

memory-fs@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.5.0.tgz#324c01288b88652966d161db77838720845a8e3c"
integrity sha512-jA0rdU5KoQMC0e6ppoNRtpp6vjFq6+NY7r8hywnC7V+1Xj/MtHwGIbB1QaK/dunyjWteJzmkpd7ooeWg10T7GA==
dependencies:
errno "^0.1.3"
readable-stream "^2.0.1"

meow@^3.3.0, meow@^3.7.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb"
Expand Down Expand Up @@ -14820,6 +14842,25 @@ ts-pnp@^1.1.2:
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.1.4.tgz#ae27126960ebaefb874c6d7fa4729729ab200d90"
integrity sha512-1J/vefLC+BWSo+qe8OnJQfWTYRS6ingxjwqmHMqaMxXMj7kFtKLgAaYW3JeX3mktjgUL+etlU8/B4VUAUI9QGw==

tsconfig-paths-webpack-plugin@3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/tsconfig-paths-webpack-plugin/-/tsconfig-paths-webpack-plugin-3.2.0.tgz#6e70bd42915ad0efb64d3385163f0c1270f3e04d"
integrity sha512-S/gOOPOkV8rIL4LurZ1vUdYCVgo15iX9ZMJ6wx6w2OgcpT/G4wMyHB6WM+xheSqGMrWKuxFul+aXpCju3wmj/g==
dependencies:
chalk "^2.3.0"
enhanced-resolve "^4.0.0"
tsconfig-paths "^3.4.0"

tsconfig-paths@^3.4.0:
version "3.9.0"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz#098547a6c4448807e8fcb8eae081064ee9a3c90b"
integrity sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==
dependencies:
"@types/json5" "^0.0.29"
json5 "^1.0.1"
minimist "^1.2.0"
strip-bom "^3.0.0"

tslib@1.10.0, tslib@^1.8.1, tslib@^1.9.3:
version "1.10.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
Expand Down

0 comments on commit 75ccd2d

Please sign in to comment.