Skip to content

Commit

Permalink
test: remove __webpack_require__.r in every import test
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Jan 13, 2024
1 parent cd26c95 commit 69c4f93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
24 changes: 12 additions & 12 deletions packages/webcrack/src/unpack/test/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ describe('webpack 4', () => {

test('namespace object', () =>
expectJS(`
var lib_namespaceObject = {};
__webpack_require__.d(lib_namespaceObject, "foo", function() { return foo; });
function foo() {}
`).toMatchInlineSnapshot(`
var lib_namespaceObject = {};
//webcrack:concatenated-module-export
Object.defineProperty(lib_namespaceObject, "foo", {
enumerable: true,
get: () => foo
});
function foo() {}
`));
var lib_namespaceObject = {};
__webpack_require__.d(lib_namespaceObject, "foo", function() { return foo; });
function foo() {}
`).toMatchInlineSnapshot(`
var lib_namespaceObject = {};
//webcrack:concatenated-module-export
Object.defineProperty(lib_namespaceObject, "foo", {
enumerable: true,
get: () => foo
});
function foo() {}
`));
});

describe('webpack 5', () => {
Expand Down
14 changes: 1 addition & 13 deletions packages/webcrack/src/unpack/test/imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const expectJS = testWebpackModuleTransform();
describe('webpack 4', () => {
test('default import', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
const lib = __webpack_require__("lib");
console.log(lib.default);
`).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -37,7 +36,6 @@ describe('webpack 4', () => {

test('named import', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
const lib = __webpack_require__("lib");
console.log(lib.foo);
`).toMatchInlineSnapshot(`
Expand All @@ -47,7 +45,6 @@ describe('webpack 4', () => {

test('multiple named imports', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
const lib = __webpack_require__("lib");
console.log(lib.foo, lib.foo, lib.bar);
`).toMatchInlineSnapshot(`
Expand All @@ -57,7 +54,6 @@ describe('webpack 4', () => {

test('named import with indirect call', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
const lib = __webpack_require__("lib");
console.log(Object(lib.foo)("bar"));
`).toMatchInlineSnapshot(`
Expand All @@ -67,7 +63,6 @@ describe('webpack 4', () => {

test('namespace import', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
const lib = __webpack_require__("lib");
console.log(lib);
`).toMatchInlineSnapshot(`
Expand All @@ -77,7 +72,6 @@ describe('webpack 4', () => {

test('combined namespace and default import', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
const lib = __webpack_require__("lib");
console.log(lib, lib.default);
`).toMatchInlineSnapshot(`
Expand All @@ -89,7 +83,6 @@ describe('webpack 4', () => {
// TODO: maybe theres no var or it got inlined somewhere
test('side effect import', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
var lib = __webpack_require__("lib");
`).toMatchInlineSnapshot(`
import "lib";
Expand All @@ -109,7 +102,6 @@ describe('webpack 4', () => {

test('indirect calls', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
const lib = __webpack_require__("lib");
console.log(Object(lib.foo)("bar"));
console.log(Object(lib.default)("bar"));
Expand All @@ -121,7 +113,6 @@ describe('webpack 4', () => {

test('sort import specifiers alphabetically', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
const lib = __webpack_require__("lib");
console.log(lib.xyz, lib.abc);
`).toMatchInlineSnapshot(`
Expand All @@ -132,7 +123,6 @@ describe('webpack 4', () => {
test.todo('hoist imports', () =>
expectJS(`
var _tmp;
__webpack_require__.r(__webpack_exports__);
var lib = __webpack_require__("lib");
var lib2 = __webpack_require__("lib2");
console.log(lib, lib2);
Expand All @@ -144,9 +134,9 @@ describe('webpack 4', () => {
`),
);

// TODO: also create an import for the 2nd require call?
test('mixed import/require', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
var lib = __webpack_require__("lib");
console.log(lib, __webpack_require__("lib2"));
`).toMatchInlineSnapshot(`
Expand All @@ -158,7 +148,6 @@ describe('webpack 4', () => {
describe('webpack 5', () => {
test('named import with indirect call', () =>
expectJS(`
__webpack_require__.r(__webpack_exports__);
const lib = __webpack_require__("lib");
console.log((0, lib.foo)("bar"));
`).toMatchInlineSnapshot(`
Expand All @@ -169,7 +158,6 @@ describe('webpack 5', () => {
test.todo('namespace import of commonjs module', () =>
expectJS(`
var _cache;
__webpack_require__.r(__webpack_exports__);
const lib = __webpack_require__("lib");
console.log(_cache ||= __webpack_require__.t(lib, 2));
`).toMatchInlineSnapshot(`
Expand Down

0 comments on commit 69c4f93

Please sign in to comment.