-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into polish-error-overlay-diff-style
- Loading branch information
Showing
3 changed files
with
109 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { mkdtemp, writeFile } from 'node:fs/promises' | ||
import { join } from 'node:path' | ||
import { tmpdir } from 'node:os' | ||
import { findConfig } from './find-config' | ||
|
||
describe('findConfig()', () => { | ||
const exampleConfig = { | ||
basePath: '/docs', | ||
} | ||
const configCode = { | ||
mjs: ` | ||
const config = ${JSON.stringify(exampleConfig)} | ||
export default config; | ||
`, | ||
cjs: ` | ||
const config = ${JSON.stringify(exampleConfig)} | ||
module.exports = config; | ||
`, | ||
} | ||
type TestPatterns = { | ||
pkgConfigTypes: ('module' | 'commonjs')[] | ||
exts: ('js' | 'mjs' | 'cjs')[] | ||
} | ||
const testPatterns: TestPatterns = { | ||
pkgConfigTypes: ['module', 'commonjs'], | ||
exts: ['js', 'mjs', 'cjs'], | ||
} | ||
|
||
for (const pkgConfigType of testPatterns.pkgConfigTypes) { | ||
for (const ext of testPatterns.exts) { | ||
it(`should load config properly from *.config.* file (type: "${pkgConfigType}", config: awsome.config.${ext})`, async () => { | ||
// Create fixtures | ||
const tmpDir = await mkdtemp(join(tmpdir(), 'nextjs-test-')) | ||
|
||
await writeFile( | ||
join(tmpDir, 'package.json'), | ||
JSON.stringify({ | ||
name: 'nextjs-test', | ||
type: pkgConfigType, | ||
}) | ||
) | ||
|
||
let configCodeType = ext | ||
if (configCodeType === 'js') { | ||
configCodeType = pkgConfigType === 'module' ? 'mjs' : 'cjs' | ||
} | ||
await writeFile( | ||
join(tmpDir, `awsome.config.${ext}`), | ||
configCode[configCodeType] | ||
) | ||
|
||
// Test | ||
const actualConfig = await findConfig(tmpDir, 'awsome') | ||
expect(actualConfig).toStrictEqual(exampleConfig) | ||
}) | ||
} | ||
} | ||
|
||
it(`should load config properly from the config in package.json)`, async () => { | ||
// Create fixtures | ||
const tmpDir = await mkdtemp(join(tmpdir(), 'nextjs-test-')) | ||
|
||
await writeFile( | ||
join(tmpDir, 'package.json'), | ||
JSON.stringify({ | ||
name: 'nextjs-test', | ||
awsome: { | ||
basePath: '/docs', | ||
}, | ||
}) | ||
) | ||
|
||
// Test | ||
const actualConfig = await findConfig(tmpDir, 'awsome') | ||
expect(actualConfig).toStrictEqual(exampleConfig) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters