Skip to content

Commit 358574e

Browse files
committed
chore: update
1 parent fcf925d commit 358574e

File tree

7 files changed

+150
-115
lines changed

7 files changed

+150
-115
lines changed

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

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -12,92 +12,6 @@ export { draft_rslib_entry_namespaceObject as default };
1212
"
1313
`;
1414

15-
exports[`use json 1`] = `
16-
"var data_namespaceObject = {
17-
R: 1,
18-
K: [
19-
"2"
20-
]
21-
};
22-
console.log(data_namespaceObject.R);
23-
console.log(data_namespaceObject.K);
24-
"
25-
`;
26-
27-
exports[`use json 2`] = `
28-
"var data_rslib_entry_namespaceObject = JSON.parse('{"foo":1,"bar":["2"]}');
29-
var __webpack_exports__bar = data_rslib_entry_namespaceObject.bar;
30-
var __webpack_exports__foo = data_rslib_entry_namespaceObject.foo;
31-
export { __webpack_exports__bar as bar, __webpack_exports__foo as foo };
32-
"
33-
`;
34-
35-
exports[`use json/yaml/toml 1`] = `
36-
"var json_example_namespaceObject = JSON.parse('{"u":"foo","e":[1,2]}');
37-
const toml_example = {
38-
hello: "world",
39-
foo: {
40-
bar: "baz"
41-
}
42-
};
43-
const yaml_example = {
44-
hello: 'world',
45-
foo: {
46-
bar: 'baz'
47-
}
48-
};
49-
console.log(json_example_namespaceObject.u);
50-
console.log(json_example_namespaceObject.e);
51-
console.log(yaml_example.hello);
52-
console.log(yaml_example.foo);
53-
console.log(toml_example.hello);
54-
console.log(toml_example.foo);
55-
"
56-
`;
57-
58-
exports[`use json/yaml/toml 2`] = `
59-
"import * as __WEBPACK_EXTERNAL_MODULE__assets_json_example_js_f9233e35__ from "./assets/json-example.js";
60-
import * as __WEBPACK_EXTERNAL_MODULE__assets_toml_example_js_83d79853__ from "./assets/toml-example.js";
61-
import * as __WEBPACK_EXTERNAL_MODULE__assets_yaml_example_js_f81ac546__ from "./assets/yaml-example.js";
62-
console.log(__WEBPACK_EXTERNAL_MODULE__assets_json_example_js_f9233e35__.name);
63-
console.log(__WEBPACK_EXTERNAL_MODULE__assets_json_example_js_f9233e35__["default"].items);
64-
console.log(__WEBPACK_EXTERNAL_MODULE__assets_yaml_example_js_f81ac546__["default"].hello);
65-
console.log(__WEBPACK_EXTERNAL_MODULE__assets_yaml_example_js_f81ac546__["default"].foo);
66-
console.log(__WEBPACK_EXTERNAL_MODULE__assets_toml_example_js_83d79853__["default"].hello);
67-
console.log(__WEBPACK_EXTERNAL_MODULE__assets_toml_example_js_83d79853__["default"].foo);
68-
"
69-
`;
70-
71-
exports[`use json/yaml/toml 3`] = `
72-
"var json_example_rslib_entry_namespaceObject = JSON.parse('{"name":"foo","items":[1,2]}');
73-
var __webpack_exports__items = json_example_rslib_entry_namespaceObject.items;
74-
var __webpack_exports__name = json_example_rslib_entry_namespaceObject.name;
75-
export { __webpack_exports__items as items, __webpack_exports__name as name };
76-
"
77-
`;
78-
79-
exports[`use json/yaml/toml 4`] = `
80-
"const yaml_example_rslib_entry_ = {
81-
hello: 'world',
82-
foo: {
83-
bar: 'baz'
84-
}
85-
};
86-
export { yaml_example_rslib_entry_ as default };
87-
"
88-
`;
89-
90-
exports[`use json/yaml/toml 5`] = `
91-
"const toml_example_rslib_entry_ = {
92-
hello: "world",
93-
foo: {
94-
bar: "baz"
95-
}
96-
};
97-
export { toml_example_rslib_entry_ as default };
98-
"
99-
`;
100-
10115
exports[`use source.assetInclude 1`] = `
10216
"import draft_namespaceObject from "./static/assets/draft.txt";
10317
console.log(draft_namespaceObject);

tests/integration/asset/index.test.ts

Lines changed: 93 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -258,36 +258,108 @@ test('set the assets public path', async () => {
258258
`);
259259
});
260260

261-
test('use json/yaml/toml', async () => {
261+
test('use json / yaml / toml', async () => {
262262
const fixturePath = join(__dirname, 'json');
263263
const { contents } = await buildAndGetResults({ fixturePath });
264264

265265
// 0. bundle
266266
// esm
267-
const { content: bundleIndexJs } = queryContent(contents.esm0!, /index\.js/);
268-
expect(bundleIndexJs).matchSnapshot();
267+
const { path: bundleIndexJs } = queryContent(contents.esm0!, /index\.js/);
268+
expect(await import(bundleIndexJs)).toMatchInlineSnapshot(`
269+
{
270+
"Object": {
271+
"jsonDefault": {
272+
"items": [
273+
1,
274+
2,
275+
],
276+
"name": "default",
277+
},
278+
"jsonNamed": {
279+
"items": [
280+
3,
281+
4,
282+
],
283+
"name": "named",
284+
},
285+
"tomlDefault": {
286+
"foo": {
287+
"bar": "baz",
288+
},
289+
"hello": "world",
290+
},
291+
"yamlDefault": {
292+
"foo": {
293+
"bar": "baz",
294+
},
295+
"hello": "world",
296+
},
297+
},
298+
}
299+
`);
269300
// 1. bundleless
270301
// esm
271-
const { content: bundlelessIndexJs } = queryContent(
272-
contents.esm1!,
273-
/index\.js/,
274-
);
275-
expect(bundlelessIndexJs).matchSnapshot();
276-
const { content: jsonFile } = queryContent(
277-
contents.esm1!,
278-
/json-example\.js/,
279-
);
280-
expect(jsonFile).matchSnapshot();
281-
const { content: yamlFile } = queryContent(
282-
contents.esm1!,
283-
/yaml-example\.js/,
284-
);
285-
expect(yamlFile).matchSnapshot();
286-
const { content: tomlFile } = queryContent(
302+
const { path: bundlelessIndexJs } = queryContent(contents.esm1!, /index\.js/);
303+
expect(await import(bundlelessIndexJs)).toMatchInlineSnapshot(`
304+
{
305+
"Object": {
306+
"jsonNamed": {
307+
"items": [
308+
3,
309+
4,
310+
],
311+
"name": "named",
312+
},
313+
"tomlDefault": {
314+
"foo": {
315+
"bar": "baz",
316+
},
317+
"hello": "world",
318+
},
319+
"yamlDefault": {
320+
"foo": {
321+
"bar": "baz",
322+
},
323+
"hello": "world",
324+
},
325+
},
326+
}
327+
`);
328+
const { path: jsonFile } = queryContent(
287329
contents.esm1!,
288-
/toml-example\.js/,
330+
/json-named-example\.js/,
289331
);
290-
expect(tomlFile).matchSnapshot();
332+
expect(await import(jsonFile)).toMatchInlineSnapshot(`
333+
{
334+
"items": [
335+
3,
336+
4,
337+
],
338+
"name": "named",
339+
}
340+
`);
341+
const { path: yamlFile } = queryContent(contents.esm1!, /yaml-example\.js/);
342+
expect(await import(yamlFile)).toMatchInlineSnapshot(`
343+
{
344+
"default": {
345+
"foo": {
346+
"bar": "baz",
347+
},
348+
"hello": "world",
349+
},
350+
}
351+
`);
352+
const { path: tomlFile } = queryContent(contents.esm1!, /toml-example\.js/);
353+
expect(await import(tomlFile)).toMatchInlineSnapshot(`
354+
{
355+
"default": {
356+
"foo": {
357+
"bar": "baz",
358+
},
359+
"hello": "world",
360+
},
361+
}
362+
`);
291363
});
292364

293365
test('use svgr', async () => {

tests/integration/asset/json/rslib.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export default defineConfig({
1313
root: './dist/esm/bundle',
1414
},
1515
},
16+
source: {
17+
entry: {
18+
index: './src/bundle.ts',
19+
},
20+
},
1621
}),
1722

1823
// 1. bundleless default
@@ -24,6 +29,15 @@ export default defineConfig({
2429
root: './dist/esm/bundleless',
2530
},
2631
},
32+
source: {
33+
entry: {
34+
index: [
35+
'./src/**/*',
36+
'!./src/bundle.ts',
37+
'!./src/assets/json-example.json',
38+
],
39+
},
40+
},
2741
}),
2842
],
2943
output: {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"name": "foo",
2+
"name": "default",
33
"items": [1, 2]
44
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "named",
3+
"items": [3, 4]
4+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import exampleJson from './assets/json-example.json';
2+
import { items, name } from './assets/json-named-example.json';
3+
import exampleToml from './assets/toml-example.toml';
4+
import exampleYaml from './assets/yaml-example.yaml';
5+
6+
export const Object = {
7+
jsonDefault: {
8+
name: exampleJson.name,
9+
items: exampleJson.items,
10+
},
11+
jsonNamed: {
12+
name,
13+
items,
14+
},
15+
yamlDefault: {
16+
hello: exampleYaml.hello,
17+
foo: exampleYaml.foo,
18+
},
19+
tomlDefault: {
20+
hello: exampleToml.hello,
21+
foo: exampleToml.foo,
22+
},
23+
};
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import exampleJson, { name } from './assets/json-example.json';
1+
import { items, name } from './assets/json-named-example.json';
22
import exampleToml from './assets/toml-example.toml';
33
import exampleYaml from './assets/yaml-example.yaml';
44

5-
console.log(name);
6-
console.log(exampleJson.items);
7-
console.log(exampleYaml.hello);
8-
console.log(exampleYaml.foo);
9-
console.log(exampleToml.hello);
10-
console.log(exampleToml.foo);
5+
export const Object = {
6+
jsonNamed: {
7+
name,
8+
items,
9+
},
10+
yamlDefault: {
11+
hello: exampleYaml.hello,
12+
foo: exampleYaml.foo,
13+
},
14+
tomlDefault: {
15+
hello: exampleToml.hello,
16+
foo: exampleToml.foo,
17+
},
18+
};

0 commit comments

Comments
 (0)