Skip to content

Commit 8c654b9

Browse files
committed
fix: update tests
1 parent e5276b8 commit 8c654b9

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/helpers/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ exports.getNextConfig = async function getNextConfig({ publish, failBuild = defa
112112

113113
const resolveModuleRoot = (moduleName) => {
114114
try {
115-
return dirname(relative(process.cwd(), require.resolve(`${moduleName}/package.json`)))
115+
return dirname(relative(process.cwd(), require.resolve(`${moduleName}/package.json`, { paths: [process.cwd()] })))
116116
} catch (error) {
117117
return null
118118
}

test/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { writeJSON, unlink, existsSync, readFileSync, copy } = require('fs-extra')
1+
const { writeJSON, unlink, existsSync, readFileSync, copy, ensureDir } = require('fs-extra')
22
const path = require('path')
33
const process = require('process')
44

@@ -42,9 +42,18 @@ const onBuildHasRun = (netlifyConfig) =>
4242

4343
// Move .next from sample project to current directory
4444
const moveNextDist = async function () {
45+
await stubModules(['next', 'react', 'react-dom', 'sharp'])
4546
await copy(path.join(SAMPLE_PROJECT_DIR, '.next'), path.join(process.cwd(), '.next'))
4647
}
4748

49+
const stubModules = async function (modules) {
50+
for (const mod of modules) {
51+
const dir = path.join(process.cwd(), 'node_modules', mod)
52+
await ensureDir(dir)
53+
await writeJSON(path.join(dir, 'package.json'), { name: mod })
54+
}
55+
}
56+
4857
// Copy fixture files to the current directory
4958
const useFixture = async function (fixtureName) {
5059
const fixtureDir = `${FIXTURES_DIR}/${fixtureName}`
@@ -185,15 +194,15 @@ describe('onBuild()', () => {
185194
'.next/serverless/**',
186195
'.next/*.json',
187196
'.next/BUILD_ID',
188-
'!node_modules/@next/swc-*/**/*',
189-
'!node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/**/*',
197+
'!../node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/**/*',
190198
'!node_modules/next/dist/pages/**/*',
191199
`!node_modules/next/dist/server/lib/squoosh/**/*.wasm`,
192200
`!node_modules/next/dist/next-server/server/lib/squoosh/**/*.wasm`,
193-
'!node_modules/next/dist/compiled/webpack/(bundle4|bundle5).js',
201+
'!node_modules/next/dist/compiled/webpack/bundle4.js',
202+
'!node_modules/next/dist/compiled/webpack/bundle5.js',
203+
'!node_modules/next/dist/compiled/terser/bundle.min.js',
194204
'!node_modules/react/**/*.development.js',
195205
'!node_modules/react-dom/**/*.development.js',
196-
'!node_modules/use-subscription/**/*.development.js',
197206
'!node_modules/sharp/**/*',
198207
]
199208
expect(netlifyConfig.functions[HANDLER_FUNCTION_NAME].included_files).toEqual(includes)

0 commit comments

Comments
 (0)