Skip to content

Commit 14f42e4

Browse files
committed
test: add json case
1 parent aee630d commit 14f42e4

File tree

6 files changed

+86
-1
lines changed

6 files changed

+86
-1
lines changed

tests/integration/asset/__snapshots__/index.test.ts.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`use json 1`] = `
4+
"JSON.parse('{"foo":1,"bar":["2"]}');
5+
"
6+
`;
7+
8+
exports[`use json 2`] = `
9+
"var data_rslib_entry_namespaceObject = JSON.parse('{"foo":1,"bar":["2"]}');
10+
var __webpack_exports__bar = data_rslib_entry_namespaceObject.bar;
11+
var __webpack_exports__foo = data_rslib_entry_namespaceObject.foo;
12+
export { __webpack_exports__bar as bar, __webpack_exports__foo as foo };
13+
"
14+
`;
15+
316
exports[`use svgr 1`] = `
417
"import __rslib_svgr_url__0__ from "./static/svg/logo.svg";
518
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";

tests/integration/asset/index.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,20 @@ test('set the assets public path', async () => {
258258
`);
259259
});
260260

261+
test('use json', async () => {
262+
const fixturePath = join(__dirname, 'json');
263+
const { contents } = await buildAndGetResults({ fixturePath });
264+
265+
// 0. bundle
266+
// esm
267+
const { content: indexJs } = queryContent(contents.esm0!, /index\.js/);
268+
expect(indexJs).matchSnapshot();
269+
// 1. bundleless
270+
// esm
271+
const { content: dataJs } = queryContent(contents.esm1!, /assets\/data\.js/);
272+
expect(dataJs).matchSnapshot();
273+
});
274+
261275
test('use svgr', async () => {
262276
const fixturePath = join(__dirname, 'svgr');
263277
const { contents } = await buildAndGetResults({ fixturePath });
@@ -271,6 +285,7 @@ test('use svgr', async () => {
271285
expect(indexCjs).matchSnapshot();
272286

273287
// 1. bundleless
288+
// esm
274289
const { content: namedImportJs } = queryContent(
275290
contents.esm1!,
276291
/namedImport\.js/,
@@ -281,7 +296,7 @@ test('use svgr', async () => {
281296
/namedImport\.js/,
282297
);
283298
expect(defaultImportJs).toMatchSnapshot();
284-
299+
// cjs
285300
const { content: namedImportCjs } = queryContent(
286301
contents.cjs1!,
287302
/namedImport\.cjs/,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "asset-types-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"dependencies": {
7+
"react": "^19.0.0"
8+
},
9+
"devDependencies": {
10+
"@rsbuild/plugin-react": "^1.1.0"
11+
}
12+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { pluginReact } from '@rsbuild/plugin-react';
2+
import { defineConfig } from '@rslib/core';
3+
import { generateBundleEsmConfig } from 'test-helper';
4+
5+
export default defineConfig({
6+
lib: [
7+
// 0. bundle default
8+
// esm
9+
generateBundleEsmConfig({
10+
output: {
11+
distPath: {
12+
root: './dist/esm/bundle',
13+
},
14+
filename: {
15+
image: '[name].[contenthash:8][ext]',
16+
},
17+
},
18+
}),
19+
20+
// 1. bundleless default
21+
// esm
22+
generateBundleEsmConfig({
23+
bundle: false,
24+
output: {
25+
distPath: {
26+
root: './dist/esm/bundleless',
27+
},
28+
filename: {
29+
image: '[name].[contenthash:16][ext]',
30+
},
31+
},
32+
}),
33+
],
34+
output: {
35+
target: 'web',
36+
},
37+
plugins: [pluginReact()],
38+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"foo": 1,
3+
"bar": ["2"]
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import a from './assets/data.json';
2+
3+
a;

0 commit comments

Comments
 (0)