Skip to content

Commit

Permalink
test: remove isWebpack5 helper
Browse files Browse the repository at this point in the history
babel-loader 9 only supports webpack 5
  • Loading branch information
JLHwung committed Jul 28, 2023
1 parent 6c2618d commit 0d361b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 41 deletions.
3 changes: 0 additions & 3 deletions test/helpers/isWebpack5.js

This file was deleted.

50 changes: 12 additions & 38 deletions test/sourcemaps.test.js
Expand Up @@ -4,7 +4,6 @@ import path from "path";
import { rimraf } from "rimraf";
import { webpackAsync } from "./helpers/webpackAsync.js";
import createTestDirectory from "./helpers/createTestDirectory.js";
import isWebpack5 from "./helpers/isWebpack5.js";

const outputDir = path.join(__dirname, "output/sourcemaps");
const babelLoader = path.join(__dirname, "../lib");
Expand Down Expand Up @@ -65,9 +64,7 @@ test("should output webpack's sourcemap", async t => {
path.resolve(t.context.directory, map[0]),
"utf8",
);
t.truthy(
sourceMapContent.includes(isWebpack5 ? "webpack://" : "webpack:///"),
);
t.truthy(sourceMapContent.includes("webpack://"));
});

test("should output webpack's sourcemap properly when set 'inline'", async t => {
Expand Down Expand Up @@ -103,17 +100,10 @@ test("should output webpack's sourcemap properly when set 'inline'", async t =>
const data = fs.readFileSync(path.resolve(t.context.directory, map[0]));
const mapObj = JSON.parse(data);

if (isWebpack5) {
t.is(mapObj.sources[3], "webpack://babel-loader/./test/fixtures/basic.js");

// Ensure that the map contains the original code, not the compiled src.
t.falsy(mapObj.sourcesContent[3].includes("__esModule"));
} else {
t.is(mapObj.sources[1], "webpack:///./test/fixtures/basic.js");
t.is(mapObj.sources[3], "webpack://babel-loader/./test/fixtures/basic.js");

// Ensure that the map contains the original code, not the compiled src.
t.falsy(mapObj.sourcesContent[1].includes("__esModule"));
}
// Ensure that the map contains the original code, not the compiled src.
t.falsy(mapObj.sourcesContent[3].includes("__esModule"));
});

test("should output webpack's devtoolModuleFilename option", async t => {
Expand Down Expand Up @@ -198,19 +188,11 @@ test("should disable sourcemap output with 'sourceMaps:false'", async t => {
const data = fs.readFileSync(path.resolve(t.context.directory, map[0]));
const mapObj = JSON.parse(data);

if (isWebpack5) {
t.is(mapObj.sources[3], "webpack://babel-loader/./test/fixtures/basic.js");
t.is(mapObj.sources[3], "webpack://babel-loader/./test/fixtures/basic.js");

// Ensure that the code contains Babel's compiled output, because
// sourcemaps from Babel are disabled.
t.truthy(mapObj.sourcesContent[3].includes("__esModule"));
} else {
t.is(mapObj.sources[1], "webpack:///./test/fixtures/basic.js");

// Ensure that the code contains Babel's compiled output, because
// sourcemaps from Babel are disabled.
t.truthy(mapObj.sourcesContent[1].includes("__esModule"));
}
// Ensure that the code contains Babel's compiled output, because
// sourcemaps from Babel are disabled.
t.truthy(mapObj.sourcesContent[3].includes("__esModule"));
});

test("should disable sourcemap output with 'sourceMap:false'", async t => {
Expand Down Expand Up @@ -246,17 +228,9 @@ test("should disable sourcemap output with 'sourceMap:false'", async t => {
const data = fs.readFileSync(path.resolve(t.context.directory, map[0]));
const mapObj = JSON.parse(data);

if (isWebpack5) {
t.is(mapObj.sources[3], "webpack://babel-loader/./test/fixtures/basic.js");

// Ensure that the code contains Babel's compiled output, because
// sourcemaps from Babel are disabled.
t.truthy(mapObj.sourcesContent[3].includes("__esModule"));
} else {
t.is(mapObj.sources[1], "webpack:///./test/fixtures/basic.js");
t.is(mapObj.sources[3], "webpack://babel-loader/./test/fixtures/basic.js");

// Ensure that the code contains Babel's compiled output, because
// sourcemaps from Babel are disabled.
t.truthy(mapObj.sourcesContent[1].includes("__esModule"));
}
// Ensure that the code contains Babel's compiled output, because
// sourcemaps from Babel are disabled.
t.truthy(mapObj.sourcesContent[3].includes("__esModule"));
});

0 comments on commit 0d361b3

Please sign in to comment.