Skip to content

Commit bc902cc

Browse files
committed
test: fix some cases
1 parent 2c6c888 commit bc902cc

File tree

14 files changed

+437
-711
lines changed

14 files changed

+437
-711
lines changed
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`source.alias 1`] = `
4-
"const a = 'hello world';
5-
console.info(a);
4+
"console.info('hello world');
65
"
76
`;
87

98
exports[`source.alias 2`] = `
109
""use strict";
1110
var __webpack_exports__ = {};
12-
const a = 'hello world';
13-
console.info(a);
11+
let a = 'hello world';
12+
console.info('hello world');
1413
var __webpack_export_target__ = exports;
1514
for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
16-
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
17-
value: true
15+
__webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
16+
value: !0
1817
});
1918
"
2019
`;

tests/integration/auto-extension/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ describe('should respect output.filename.js to override builtin logic', () => {
4040
const { entryFiles } = await buildAndGetResults({ fixturePath });
4141
expect(extname(entryFiles.esm!)).toEqual('.mjs');
4242
expect(entryFiles.cjs).toMatchInlineSnapshot(
43-
`"<ROOT>/tests/integration/auto-extension/type-commonjs/config-override/dist/cjs/index.d08e1bb3.js"`,
43+
`"<ROOT>/tests/integration/auto-extension/type-commonjs/config-override/dist/cjs/index.60cfaf97.js"`,
4444
);
4545
});
4646

4747
test('type is module', async () => {
4848
const fixturePath = join(__dirname, 'type-module', 'config-override');
4949
const { entryFiles } = await buildAndGetResults({ fixturePath });
5050
expect(entryFiles.esm).toMatchInlineSnapshot(
51-
`"<ROOT>/tests/integration/auto-extension/type-module/config-override/dist/esm/index.d2068839.js"`,
51+
`"<ROOT>/tests/integration/auto-extension/type-module/config-override/dist/esm/index.387ba858.js"`,
5252
);
5353
expect(extname(entryFiles.cjs!)).toEqual('.cjs');
5454
});

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

Lines changed: 362 additions & 596 deletions
Large diffs are not rendered by default.

tests/integration/extension-alias/__snapshots__/index.test.ts.snap

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33
exports[`resolve.extensionAlias should work 1`] = `
44
""use strict";
55
var __webpack_exports__ = {};
6-
const bar = 'bar';
7-
const foo = 'foo';
6+
let bar = 'bar', foo = 'foo';
87
// Relative import paths need explicit file extensions in ECMAScript imports
98
// when '--moduleResolution' is 'node16' or 'nodenext'.
10-
console.log(foo + bar);
9+
console.log("foobar");
1110
var __webpack_export_target__ = exports;
1211
for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
13-
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
14-
value: true
12+
__webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
13+
value: !0
1514
});
1615
"
1716
`;
1817

1918
exports[`resolve.extensionAlias should work 2`] = `
20-
"const bar = 'bar';
21-
const foo = 'foo';
22-
// Relative import paths need explicit file extensions in ECMAScript imports
19+
"// Relative import paths need explicit file extensions in ECMAScript imports
2320
// when '--moduleResolution' is 'node16' or 'nodenext'.
24-
console.log(foo + bar);
21+
console.log("foobar");
2522
"
2623
`;

tests/integration/external-helpers/__snapshots__/index.test.ts.snap

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ var src_FOO = /*#__PURE__*/ function() {
88
function FOO() {
99
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check__._)(this, FOO);
1010
}
11-
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__._)(FOO, [
11+
return (0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__._)(FOO, [
1212
{
1313
key: "bar",
1414
get: function() {}
1515
}
16-
]);
17-
return FOO;
16+
]), FOO;
1817
}();
1918
export { src_FOO as default };
2019
"
@@ -28,83 +27,64 @@ var src_FOO = /*#__PURE__*/ function() {
2827
function FOO() {
2928
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check__._)(this, FOO);
3029
}
31-
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__._)(FOO, [
30+
return (0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__._)(FOO, [
3231
{
3332
key: "bar",
3433
get: function() {}
3534
}
36-
]);
37-
return FOO;
35+
]), FOO;
3836
}();
3937
export { src_FOO as default };
4038
"
4139
`;
4240

4341
exports[`should not external @swc/helpers by default 1`] = `
44-
"function _class_call_check(instance, Constructor) {
45-
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
46-
}
47-
function _defineProperties(target, props) {
42+
"function _defineProperties(target, props) {
4843
for(var i = 0; i < props.length; i++){
4944
var descriptor = props[i];
50-
descriptor.enumerable = descriptor.enumerable || false;
51-
descriptor.configurable = true;
52-
if ("value" in descriptor) descriptor.writable = true;
53-
Object.defineProperty(target, descriptor.key, descriptor);
45+
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor);
5446
}
5547
}
56-
function _create_class(Constructor, protoProps, staticProps) {
57-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
58-
if (staticProps) _defineProperties(Constructor, staticProps);
59-
return Constructor;
60-
}
6148
var src_FOO = /*#__PURE__*/ function() {
6249
"use strict";
50+
var Constructor, protoProps, staticProps;
6351
function FOO() {
64-
_class_call_check(this, FOO);
52+
!function(instance, Constructor) {
53+
if (!(instance instanceof Constructor)) throw TypeError("Cannot call a class as a function");
54+
}(this, FOO);
6555
}
66-
_create_class(FOO, [
56+
return Constructor = FOO, protoProps = [
6757
{
6858
key: "bar",
6959
get: function() {}
7060
}
71-
]);
72-
return FOO;
61+
], _defineProperties(Constructor.prototype, protoProps), FOO;
7362
}();
7463
export { src_FOO as default };
7564
"
7665
`;
7766

7867
exports[`should respect user override externalHelpers config 1`] = `
79-
"function _class_call_check(instance, Constructor) {
80-
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
81-
}
82-
function _defineProperties(target, props) {
68+
"function _defineProperties(target, props) {
8369
for(var i = 0; i < props.length; i++){
8470
var descriptor = props[i];
85-
descriptor.enumerable = descriptor.enumerable || false;
86-
descriptor.configurable = true;
87-
if ("value" in descriptor) descriptor.writable = true;
88-
Object.defineProperty(target, descriptor.key, descriptor);
71+
descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor);
8972
}
9073
}
91-
function _create_class(Constructor, protoProps, staticProps) {
92-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
93-
if (staticProps) _defineProperties(Constructor, staticProps);
94-
return Constructor;
95-
}
9674
var src_FOO = /*#__PURE__*/ function() {
9775
"use strict";
76+
var Constructor, protoProps, staticProps;
9877
function FOO() {
99-
_class_call_check(this, FOO);
78+
!function(instance, Constructor) {
79+
if (!(instance instanceof Constructor)) throw TypeError("Cannot call a class as a function");
80+
}(this, FOO);
10081
}
101-
_create_class(FOO, [
82+
return Constructor = FOO, protoProps = [
10283
{
10384
key: "bar",
10485
get: function() {}
10586
}
106-
]);
107-
return FOO;
87+
], _defineProperties(Constructor.prototype, protoProps), FOO;
10888
}();
10989
export { src_FOO as default };
11090
"
@@ -118,13 +98,12 @@ var src_FOO = /*#__PURE__*/ function() {
11898
function FOO() {
11999
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check__._)(this, FOO);
120100
}
121-
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__._)(FOO, [
101+
return (0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__._)(FOO, [
122102
{
123103
key: "bar",
124104
get: function() {}
125105
}
126-
]);
127-
return FOO;
106+
]), FOO;
128107
}();
129108
export { src_FOO as default };
130109
"

tests/integration/minify/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test('tree shaking is enabled by default, bar and baz should be shaken', async (
66
const fixturePath = join(__dirname, 'default');
77
const { entries } = await buildAndGetResults({ fixturePath });
88
expect(entries.esm).toMatchInlineSnapshot(`
9-
"const foo = ()=>{};
9+
"let foo = ()=>{};
1010
export { foo };
1111
"
1212
`);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const i1 = import(`${process.env.DIR}./other`);
22
const i2 = import(process.env.DIR!);
3-
const condition = 1 > 0;
3+
const condition = Math.random() > 0.5;
44
const i3 = import(condition ? './other1' : './other2');
55
export { i1, i2, i3 };

tests/integration/require/index.test.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@ test('require.resolve', async () => {
77
const { entries } = await buildAndGetResults({ fixturePath });
88

99
const statements = [
10-
"const cjs1 = require.resolve('./other')",
11-
'const cjs2 = require.resolve(`${process.env.DIR}./other`)',
12-
'const assignedResolve = require.resolve',
13-
"const cjs3 = assignedResolve('./other')",
14-
"const cr1 = _require.resolve('./other')",
15-
'const cr2 = _require.resolve(`${process.env.DIR}./other`)',
16-
'const assignedResolve2 = _require.resolve',
17-
"const cr3 = assignedResolve2('./other')",
10+
"let cjs1 = require.resolve('./other')",
11+
'cjs2 = require.resolve(`${process.env.DIR}./other`)',
12+
"cjs3 = (0, require.resolve)('./other')",
13+
"cr1 = _require.resolve('./other')",
14+
'cr2 = _require.resolve(`${process.env.DIR}./other`)',
15+
"cr3 = (0, _require.resolve)('./other')",
1816
];
1917

2018
const esmStatements = [
2119
'import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module"',
22-
'const _require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url)',
20+
'_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url)',
2321
];
2422

2523
const cjsStatements = [
26-
'const _require = (0, external_node_module_namespaceObject.createRequire)(',
24+
'_require = (0, external_node_module_namespaceObject.createRequire)(',
2725
];
2826

2927
for (const statement of [...statements, ...esmStatements]) {
@@ -48,11 +46,11 @@ test('require dynamic', async () => {
4846

4947
const esmStatements = [
5048
'import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module"',
51-
'const _require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url)',
49+
'_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url)',
5250
];
5351

5452
const cjsStatements = [
55-
'const _require = (0, external_node_module_namespaceObject.createRequire)(',
53+
'_require = (0, external_node_module_namespaceObject.createRequire)(',
5654
];
5755

5856
for (const statement of [...statements, ...esmStatements]) {
@@ -69,9 +67,9 @@ test('import dynamic', async () => {
6967
const { entries } = await buildAndGetResults({ fixturePath });
7068

7169
const statements = [
72-
'const i1 = import(`${process.env.DIR}./other`)',
73-
'const i2 = import(process.env.DIR)',
74-
"const i3 = import(condition ? './other1' : './other2')",
70+
'let i1 = import(`${process.env.DIR}./other`)',
71+
'i2 = import(process.env.DIR)',
72+
"i3 = import(Math.random() > 0.5 ? './other1' : './other2')",
7573
];
7674

7775
for (const statement of [...statements]) {
@@ -87,15 +85,13 @@ test('require as expression', async () => {
8785
const fixturePath = join(__dirname, 'require-as-expression');
8886
const { entries } = await buildAndGetResults({ fixturePath });
8987

88+
expect(entries.esm).toContain(`console.log('./other.js', require);`);
89+
9090
const statements = [
91-
'const lazyFn = (module, requireFn)=>{}',
91+
'let lazyFn = (module, requireFn)=>{',
9292
"lazyFn('./other.js', require)",
9393
];
9494

95-
for (const statement of [...statements]) {
96-
expect(entries.esm).toContain(statement);
97-
}
98-
9995
for (const statement of [...statements]) {
10096
expect(entries.cjs).toContain(statement);
10197
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
const lazyFn = (module, requireFn) => {};
1+
const lazyFn = (module, requireFn) => {
2+
requireFn(module);
3+
};
24
lazyFn('./other.js', require);

tests/integration/resolve/index.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ test('resolve data url', async () => {
88

99
expect(isSuccess).toBeTruthy();
1010
expect(entries.esm).toMatchInlineSnapshot(`
11-
"/* ESM default export */ const javascript_export_default_42 = 42;
12-
console.log('x:', javascript_export_default_42);
11+
"console.log('x:', 42);
1312
"
1413
`);
1514
});
@@ -31,7 +30,7 @@ test('resolve node protocol', async () => {
3130
expect(isSuccess).toBeTruthy();
3231
expect(entries.esm).toMatchInlineSnapshot(`
3332
"import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
34-
const { join } = __WEBPACK_EXTERNAL_MODULE_node_path__["default"];
33+
let { join } = __WEBPACK_EXTERNAL_MODULE_node_path__.default;
3534
export { join };
3635
"
3736
`);
@@ -63,8 +62,7 @@ test('resolve with js extensions', async () => {
6362

6463
expect(isSuccess).toBeTruthy();
6564
expect(entries.esm).toMatchInlineSnapshot(`
66-
"const value = 1;
67-
console.log(value);
65+
"console.log(1);
6866
"
6967
`);
7068
});
@@ -76,8 +74,7 @@ test('resolve with main fields', async () => {
7674

7775
expect(isSuccess).toBeTruthy();
7876
expect(Object.values(results[0]!)[0]).toMatchInlineSnapshot(`
79-
"const value = 1;
80-
console.log(value);
77+
"console.log(1);
8178
"
8279
`);
8380
expect(Object.values(results[1]!)[0]).toContain('main');

0 commit comments

Comments
 (0)