-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee00275
commit 2a60a86
Showing
12 changed files
with
368 additions
and
0 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,109 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1`] = ` | ||
[ | ||
{ | ||
"output": { | ||
"distPath": { | ||
"js": "./", | ||
}, | ||
"filenameHash": false, | ||
"minify": false, | ||
}, | ||
"source": { | ||
"alias": { | ||
"bar": "bar", | ||
"foo": "foo/esm", | ||
}, | ||
"preEntry": "./b.js", | ||
}, | ||
"tools": { | ||
"htmlPlugin": false, | ||
"rspack": { | ||
"experiments": { | ||
"outputModule": true, | ||
}, | ||
"optimization": { | ||
"concatenateModules": true, | ||
}, | ||
"output": { | ||
"library": { | ||
"type": "module", | ||
}, | ||
"module": true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"output": { | ||
"distPath": { | ||
"js": "./", | ||
}, | ||
"filenameHash": false, | ||
"minify": false, | ||
}, | ||
"source": { | ||
"alias": { | ||
"bar": "bar/cjs", | ||
"foo": "foo", | ||
}, | ||
"preEntry": [ | ||
"./a.js", | ||
"./c.js", | ||
"./d.js", | ||
], | ||
}, | ||
"tools": { | ||
"htmlPlugin": false, | ||
"rspack": { | ||
"experiments": { | ||
"outputModule": true, | ||
}, | ||
"optimization": { | ||
"concatenateModules": true, | ||
}, | ||
"output": { | ||
"library": { | ||
"type": "module", | ||
}, | ||
"module": true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"output": { | ||
"distPath": { | ||
"js": "./", | ||
}, | ||
"filenameHash": false, | ||
"minify": false, | ||
}, | ||
"source": { | ||
"alias": { | ||
"bar": "bar", | ||
"foo": "foo", | ||
}, | ||
"preEntry": "./a.js", | ||
}, | ||
"tools": { | ||
"htmlPlugin": false, | ||
"rspack": { | ||
"experiments": { | ||
"outputModule": true, | ||
}, | ||
"optimization": { | ||
"concatenateModules": true, | ||
}, | ||
"output": { | ||
"library": { | ||
"type": "module", | ||
}, | ||
"module": true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
] | ||
`; |
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,185 @@ | ||
import { join } from 'node:path'; | ||
import { describe, expect, test } from 'vitest'; | ||
import { composeCreateRsbuildConfig, loadConfig } from '../src/config'; | ||
import type { RslibConfig } from '../src/types/config'; | ||
|
||
describe('Should load config file correctly', () => { | ||
test('Load config.js in cjs project', async () => { | ||
const fixtureDir = join(__dirname, 'config/cjs'); | ||
const configDir = join(fixtureDir, 'rslib.config.js'); | ||
const config = await loadConfig(configDir); | ||
expect(config).toEqual({ | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
_privateMeta: { | ||
configFilePath: configDir, | ||
}, | ||
}); | ||
}); | ||
|
||
test('Load config.mjs in cjs project', async () => { | ||
const fixtureDir = join(__dirname, 'config/cjs'); | ||
const configDir = join(fixtureDir, 'rslib.config.mjs'); | ||
const config = await loadConfig(configDir); | ||
expect(config).toEqual({ | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
_privateMeta: { | ||
configFilePath: configDir, | ||
}, | ||
}); | ||
}); | ||
|
||
test('Load config.ts in cjs project', async () => { | ||
const fixtureDir = join(__dirname, 'config/cjs'); | ||
const configDir = join(fixtureDir, 'rslib.config.ts'); | ||
const config = await loadConfig(configDir); | ||
expect(config).toEqual({ | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.ts', | ||
}, | ||
}, | ||
_privateMeta: { | ||
configFilePath: configDir, | ||
}, | ||
}); | ||
}); | ||
|
||
test('Load config.cjs with defineConfig in cjs project', async () => { | ||
const fixtureDir = join(__dirname, 'config/cjs'); | ||
const configDir = join(fixtureDir, 'rslib.config.cjs'); | ||
const config = await loadConfig(configDir); | ||
expect(config).toEqual({ | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
_privateMeta: { | ||
configFilePath: configDir, | ||
}, | ||
}); | ||
}); | ||
|
||
test('Load config.js in esm project', async () => { | ||
const fixtureDir = join(__dirname, 'config/esm'); | ||
const configDir = join(fixtureDir, 'rslib.config.js'); | ||
const config = await loadConfig(configDir); | ||
expect(config).toEqual({ | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
_privateMeta: { | ||
configFilePath: configDir, | ||
}, | ||
}); | ||
}); | ||
|
||
test('Load config.cjs in esm project', async () => { | ||
const fixtureDir = join(__dirname, 'config/esm'); | ||
const configDir = join(fixtureDir, 'rslib.config.cjs'); | ||
const config = await loadConfig(configDir); | ||
expect(config).toEqual({ | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
_privateMeta: { | ||
configFilePath: configDir, | ||
}, | ||
}); | ||
}); | ||
|
||
test('Load config.ts in esm project', async () => { | ||
const fixtureDir = join(__dirname, 'config/esm'); | ||
const configDir = join(fixtureDir, 'rslib.config.ts'); | ||
const config = await loadConfig(configDir); | ||
expect(config).toEqual({ | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.ts', | ||
}, | ||
}, | ||
_privateMeta: { | ||
configFilePath: configDir, | ||
}, | ||
}); | ||
}); | ||
|
||
test('Load config.mjs with defineConfig in esm project', async () => { | ||
const fixtureDir = join(__dirname, 'config/esm'); | ||
const configDir = join(fixtureDir, 'rslib.config.mjs'); | ||
const config = await loadConfig(configDir); | ||
expect(config).toEqual({ | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
_privateMeta: { | ||
configFilePath: configDir, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Should compose create Rsbuild config correctly', () => { | ||
test('Merge Rsbuild config', async () => { | ||
const rslibConfig: RslibConfig = { | ||
lib: [ | ||
{ | ||
format: 'esm', | ||
source: { | ||
alias: { | ||
foo: 'foo/esm', | ||
}, | ||
preEntry: './b.js', | ||
}, | ||
}, | ||
{ | ||
format: 'cjs', | ||
source: { | ||
alias: { | ||
bar: 'bar/cjs', | ||
}, | ||
preEntry: ['./c.js', './d.js'], | ||
}, | ||
}, | ||
{ | ||
format: 'umd', | ||
}, | ||
], | ||
source: { | ||
alias: { | ||
foo: 'foo', | ||
bar: 'bar', | ||
}, | ||
preEntry: './a.js', | ||
}, | ||
output: { | ||
filenameHash: false, | ||
minify: true, | ||
}, | ||
}; | ||
const composedRsbuildConfig = await composeCreateRsbuildConfig(rslibConfig); | ||
expect(composedRsbuildConfig).toMatchSnapshot(); | ||
}); | ||
}); |
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,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
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,10 @@ | ||
const { defineConfig } = require('../../../../core/src/config'); | ||
|
||
module.exports = defineConfig((args) => ({ | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
})); |
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,8 @@ | ||
module.exports = { | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
}; |
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,8 @@ | ||
export default { | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
}; |
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,8 @@ | ||
export default { | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.ts', | ||
}, | ||
}, | ||
}; |
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,3 @@ | ||
{ | ||
"type": "module" | ||
} |
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,8 @@ | ||
module.exports = { | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
}; |
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,8 @@ | ||
export default { | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
}; |
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,10 @@ | ||
import { defineConfig } from '../../../../core/src/config'; | ||
|
||
export default defineConfig((args) => ({ | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.js', | ||
}, | ||
}, | ||
})); |
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,8 @@ | ||
export default { | ||
lib: [], | ||
source: { | ||
entry: { | ||
main: './foo/index.ts', | ||
}, | ||
}, | ||
}; |