Skip to content

Commit a7bd23d

Browse files
authored
test: add sourcemap tests (#187)
1 parent d842231 commit a7bd23d

File tree

12 files changed

+141
-5
lines changed

12 files changed

+141
-5
lines changed

e2e/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Rslib will try to cover the common scenarios in the [integration test cases of M
3434
| shims | 🟡 | Support shims `__filename` and `__dirname` in esm</br> `import.meta.url` in cjs need to be supported |
3535
| sideEffects | ⚪️ | |
3636
| sourceDir | ⚪️ | |
37-
| sourceMap | ⚪️ | |
37+
| sourceMap | 🟢 | |
3838
| splitting | ⚪️ | |
3939
| style | ⚪️ | |
4040
| target | 🟢 | |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "@rslib/tsconfig/base",
3+
"compilerOptions": {
4+
"baseUrl": "./"
5+
},
6+
"include": ["src"]
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "sourcemap-default-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [generateBundleEsmConfig()],
6+
source: {
7+
entry: {
8+
index: '../__fixtures__/src/index.ts',
9+
},
10+
},
11+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "sourcemap-external-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [generateBundleEsmConfig()],
6+
source: {
7+
entry: {
8+
index: '../__fixtures__/src/index.ts',
9+
},
10+
},
11+
output: {
12+
sourceMap: {
13+
js: 'cheap-module-source-map',
14+
},
15+
},
16+
});

e2e/cases/sourcemap/index.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os from 'node:os';
2+
import { join } from 'node:path';
3+
import { buildAndGetResults } from '@e2e/helper';
4+
import { expect, test } from 'vitest';
5+
6+
test('should not generate js sourcemap by default', async () => {
7+
const fixturePath = join(__dirname, 'default');
8+
const { contents } = await buildAndGetResults(fixturePath, 'js');
9+
const files = Object.keys(contents.esm);
10+
11+
expect(files).toMatchInlineSnapshot(`
12+
[
13+
"<ROOT>/e2e/cases/sourcemap/default/dist/esm/index.js",
14+
]
15+
`);
16+
});
17+
18+
test('should generate js external sourcemap: cheap-module-source-map', async () => {
19+
const fixturePath = join(__dirname, 'external');
20+
const { contents } = await buildAndGetResults(fixturePath, 'js');
21+
const files = Object.keys(contents.esm);
22+
23+
expect(files).toMatchInlineSnapshot(`
24+
[
25+
"<ROOT>/e2e/cases/sourcemap/external/dist/esm/index.js",
26+
"<ROOT>/e2e/cases/sourcemap/external/dist/esm/index.js.map",
27+
]
28+
`);
29+
});
30+
31+
test('should generate js inline sourcemap: inline-cheap-module-source-map', async () => {
32+
const fixturePath = join(__dirname, 'inline');
33+
const { contents } = await buildAndGetResults(fixturePath, 'js');
34+
const files = Object.keys(contents.esm);
35+
const code = Object.values(contents.esm);
36+
37+
expect(files).toMatchInlineSnapshot(`
38+
[
39+
"<ROOT>/e2e/cases/sourcemap/inline/dist/esm/index.js",
40+
]
41+
`);
42+
43+
if (os.platform() === 'win32') {
44+
expect(code).toMatchInlineSnapshot(`
45+
[
46+
"const foo = 'foo';
47+
export { foo };
48+
49+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9zb3VyY2VtYXAtaW5saW5lLXRlc3QvLi4vX19maXh0dXJlc19fL3NyYy9pbmRleC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgY29uc3QgZm9vID0gJ2Zvbyc7XHJcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9",
50+
]
51+
`);
52+
} else {
53+
expect(code).toMatchInlineSnapshot(`
54+
[
55+
"const foo = 'foo';
56+
export { foo };
57+
58+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9zb3VyY2VtYXAtaW5saW5lLXRlc3QvLi4vX19maXh0dXJlc19fL3NyYy9pbmRleC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgY29uc3QgZm9vID0gJ2Zvbyc7XG4iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==",
59+
]
60+
`);
61+
}
62+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "sourcemap-inline-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [generateBundleEsmConfig()],
6+
source: {
7+
entry: {
8+
index: '../__fixtures__/src/index.ts',
9+
},
10+
},
11+
output: {
12+
sourceMap: {
13+
js: 'inline-cheap-module-source-map',
14+
},
15+
},
16+
});

e2e/scripts/shared.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,13 @@ export async function getResults(
9090

9191
const regex =
9292
type === 'dts'
93-
? /\.d.(ts|cts|mts)$/
93+
? /\.d.(ts|cts|mts)(\.map)?$/
9494
: type === 'css'
95-
? /\.css$/
96-
: /\.(js|cjs|mjs)$/;
95+
? /\.css(\.map)?$/
96+
: /\.(js|cjs|mjs)(\.map)?$/;
9797

9898
const content: Record<string, string> = await globContentJSON(globFolder, {
9999
absolute: true,
100-
ignore: ['**/*.map'],
101100
});
102101

103102
const fileSet = Object.keys(content)

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)