Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split jsconfig-paths and jsconfig-paths-wildcard tests #57360

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/integration/jsconfig-paths-wildcard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules
8 changes: 8 additions & 0 deletions test/integration/jsconfig-paths-wildcard/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": ["node_modules/*"]
}
}
}
6 changes: 6 additions & 0 deletions test/integration/jsconfig-paths-wildcard/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions test/integration/jsconfig-paths-wildcard/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-env jest */

import { join } from 'path'
import cheerio from 'cheerio'
import * as path from 'path'
import {
renderViaHTTP,
findPort,
launchApp,
killApp,
File,
} from 'next-test-utils'
import * as JSON5 from 'json5'

const appDir = join(__dirname, '..')
let appPort
let app

async function get$(path, query) {
const html = await renderViaHTTP(appPort, path, query)
return cheerio.load(html)
}

function runTests() {
describe('default behavior', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))

it('should resolve a wildcard alias', async () => {
const $ = await get$('/wildcard-alias')
expect($('body').text()).toMatch(/world/)
})
})
}

describe('jsconfig paths wildcard', () => {
runTests()
})

const jsconfig = new File(path.resolve(__dirname, '../jsconfig.json'))

describe('jsconfig paths without baseurl wildcard', () => {
beforeAll(() => {
const jsconfigContent = JSON5.parse(jsconfig.originalContent)
delete jsconfigContent.compilerOptions.baseUrl
jsconfigContent.compilerOptions.paths = {
'*': ['./node_modules/*'],
}
jsconfig.write(JSON.stringify(jsconfigContent, null, 2))
})

afterAll(() => {
jsconfig.restore()
})

runTests()
})
3 changes: 1 addition & 2 deletions test/integration/jsconfig-paths/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"paths": {
"@c/*": ["components/*"],
"@lib/*": ["lib/a/*", "lib/b/*"],
"@mycomponent": ["components/hello.js"],
"*": ["node_modules/*"]
"@mycomponent": ["components/hello.js"]
}
}
}
45 changes: 16 additions & 29 deletions test/integration/jsconfig-paths/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,26 @@ function runTests() {
expect($('body').text()).toMatch(/Hello/)
})

it('should resolve a wildcard alias', async () => {
const $ = await get$('/wildcard-alias')
expect($('body').text()).toMatch(/world/)
})

it('should have correct module not found error', async () => {
const basicPage = join(appDir, 'pages/basic-alias.js')
const contents = await fs.readFile(basicPage, 'utf8')

await fs.writeFile(basicPage, contents.replace('@c/world', '@c/worldd'))
await renderViaHTTP(appPort, '/basic-alias')

const found = await check(
() => stripAnsi(output),
/Module not found: Can't resolve '@c\/worldd'/,
false
)
await fs.writeFile(basicPage, contents)
expect(found).toBe(true)
try {
await fs.writeFile(basicPage, contents.replace('@c/world', '@c/worldd'))
await renderViaHTTP(appPort, '/basic-alias')

const found = await check(
() => stripAnsi(output),
process.env.TURBOPACK
? /unable to resolve module "@c\/worldd"/
: /Module not found: Can't resolve '@c\/worldd'/,
false,
10
)
expect(found).toBe(true)
} finally {
await fs.writeFile(basicPage, contents)
}
})
})

Expand All @@ -95,9 +96,6 @@ function runTests() {
const singleAliasTrace = await fs.readJSON(
join(appDir, '.next/server/pages/single-alias.js.nft.json')
)
const wildcardAliasTrace = await fs.readJSON(
join(appDir, '.next/server/pages/wildcard-alias.js.nft.json')
)
const resolveOrderTrace = await fs.readJSON(
join(appDir, '.next/server/pages/resolve-order.js.nft.json')
)
Expand All @@ -113,16 +111,6 @@ function runTests() {
file.includes('components/hello.js')
)
).toBe(false)
expect(
wildcardAliasTrace.files.some((file) =>
file.includes('mypackage/myfile.js')
)
).toBe(true)
expect(
wildcardAliasTrace.files.some((file) =>
file.includes('mypackage/data.js')
)
).toBe(false)
expect(
resolveOrderTrace.files.some((file) =>
file.includes('lib/a/api.js')
Expand Down Expand Up @@ -163,7 +151,6 @@ describe('jsconfig paths without baseurl', () => {
'@c/*': ['./components/*'],
'@lib/*': ['./lib/a/*', './lib/b/*'],
'@mycomponent': ['./components/hello.js'],
'*': ['./node_modules/*'],
}
jsconfig.write(JSON.stringify(jsconfigContent, null, 2))
})
Expand Down
Loading