Skip to content

Commit fe72cca

Browse files
committed
Revert back to __dirname for browser tests
Karma configuration needs to upgrade to Webpack 5 in order to use import.meta.url
1 parent e55ce71 commit fe72cca

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

lib/util/projectDir.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const nodePath = require("path");
2+
3+
// Webpack 4 (used by browser tests) can't transpile import.meta.url
4+
// So export the project directory using __dirname from a .cjs module
5+
const projectDir = nodePath.resolve(__dirname, "..", "..");
6+
module.exports = projectDir

lib/util/url.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import nodePath from "path";
2-
import { fileURLToPath } from "url"
3-
const projectDir = nodePath.resolve(fileURLToPath(new URL(".", import.meta.url)), "..", "..");
2+
import projectDir from "./projectDir.cjs";
43

54
let isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined),
65
forwardSlashPattern = /\//g,

test/utils/path.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { fileURLToPath } from "url";
21
import nodePath from "path";
32
import nodeUrl from "url";
43
import { host } from "@jsdevtools/host-environment";
4+
import projectDir from "../../lib/util/projectDir.cjs";
55

66
const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined);
77
const getPathFromOs = filePath => isWindows ? filePath.replace(/\\/g, "/") : filePath;
@@ -17,7 +17,7 @@ const pathHelpers = {
1717
function filesystemPathHelpers () {
1818

1919
if (host.node) {
20-
const testsDir = nodePath.resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
20+
const testsDir = nodePath.resolve(projectDir, "test")
2121

2222
// Run all tests from the "test" directory
2323
process.chdir(testsDir);

0 commit comments

Comments
 (0)