Skip to content

Commit 75bc27b

Browse files
author
Jozef Vojtas
committed
Keep tests isolated from node_modules
1 parent 1ea1f74 commit 75bc27b

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

tests/run.mjs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import assert from "node:assert/strict";
22
import { createHmac, timingSafeEqual } from "node:crypto";
3-
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3+
import {
4+
cpSync,
5+
mkdirSync,
6+
mkdtempSync,
7+
readFileSync,
8+
rmSync,
9+
writeFileSync,
10+
} from "node:fs";
11+
import { tmpdir } from "node:os";
412
import { dirname, join } from "node:path";
513
import { fileURLToPath, pathToFileURL } from "node:url";
614

715
const __dirname = dirname(fileURLToPath(import.meta.url));
816
const sourceRoot = join(__dirname, "..");
9-
const packageRoot = join(sourceRoot, "node_modules");
1017

1118
function writeRuntimeStub(path, source) {
1219
mkdirSync(dirname(path), { recursive: true });
1320
writeFileSync(path, source);
1421
}
1522

16-
function installRuntimeStubs() {
23+
function installRuntimeStubs(packageRoot) {
1724
rmSync(packageRoot, { force: true, recursive: true });
1825

1926
writeRuntimeStub(
@@ -178,7 +185,12 @@ function signWebhook(rawBody, secret) {
178185
}
179186

180187
async function main() {
181-
installRuntimeStubs();
188+
const runtimeRoot = mkdtempSync(join(tmpdir(), "makepay-medusa-test-"));
189+
const packageRoot = join(runtimeRoot, "node_modules");
190+
const runtimeDistRoot = join(runtimeRoot, "dist");
191+
192+
installRuntimeStubs(packageRoot);
193+
cpSync(join(sourceRoot, "dist"), runtimeDistRoot, { recursive: true });
182194

183195
try {
184196
const pkg = JSON.parse(
@@ -201,7 +213,7 @@ async function main() {
201213
}
202214

203215
const moduleUrl = pathToFileURL(
204-
join(sourceRoot, "dist/providers/makepay/index.js"),
216+
join(runtimeDistRoot, "providers/makepay/index.js"),
205217
);
206218
const makePayUrl = pathToFileURL(
207219
join(packageRoot, "@makecrypto/makepay/index.js"),
@@ -400,7 +412,7 @@ async function main() {
400412

401413
console.log("MakePay Medusa provider source verified.");
402414
} finally {
403-
rmSync(packageRoot, { force: true, recursive: true });
415+
rmSync(runtimeRoot, { force: true, recursive: true });
404416
}
405417
}
406418

0 commit comments

Comments
 (0)