Skip to content

Commit f2e52f5

Browse files
committed
fix: Make tests runable from different dir
1 parent 19ff90f commit f2e52f5

File tree

7 files changed

+34
-11
lines changed

7 files changed

+34
-11
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default {
33
globalSetup: "./jest-global-setup.ts",
44
testEnvironment: "node",
55
// Max it! Most of the wait is in network block, nothing computationally heavy
6-
maxWorkers: "80%",
6+
maxWorkers: "30%",
77
silent: true,
88
testTimeout: 180000,
99
transform: {

tests/general/sql.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { TestEnv } from "../../src/env";
22
import { buildPhpApp } from "../../src/index";
33
import * as fs from "node:fs";
4+
import path from "node:path";
5+
import { projectRoot } from "../utils/path";
46

57
test.concurrent("sql-connectivity", async () => {
68
const env = TestEnv.fromEnv();
7-
const filePath = "./fixtures/php/mysql-check.php";
9+
const filePath = path.join(projectRoot, "fixtures", "php", "mysql-check.php");
810
const testCode = await fs.promises.readFile(filePath, "utf-8");
911

1012
// Validate that DB credentials aren't setup without specifying to have it
1113
{
1214
console.log("== Setting up environment without SQL ==");
1315
const want = "Missing required SQL environment variables";
1416
const withoutSqlSpec = buildPhpApp(testCode);
15-
const withoutSqlInfo = await env.deployApp(withoutSqlSpec);
17+
const withoutSqlInfo = await env.deployApp(withoutSqlSpec, { noWait: true });
1618
const res = await env.fetchApp(withoutSqlInfo, "/results");
1719
const got = await res.text();
1820
expect(got).toContain(want);
@@ -36,7 +38,7 @@ test.concurrent("sql-connectivity", async () => {
3638
},
3739
},
3840
});
39-
const withSqlInfo = await env.deployApp(withSqlSpec);
41+
const withSqlInfo = await env.deployApp(withSqlSpec, { noWait: true });
4042

4143
{
4244
const res = await env.fetchApp(withSqlInfo, "/results");

tests/general/volumes.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { assertEquals } from "../../src/testing_tools";
55

66
import { copyPackageAnonymous } from "../../src/package";
77
import { randomAppName } from "../../src/app/construct";
8+
import { projectRoot } from "../utils/path";
89

910
import {
1011
AppDefinition,
@@ -17,7 +18,12 @@ import {
1718
test("app-volumes", async () => {
1819
const env = TestEnv.fromEnv();
1920

20-
const rootPackageDir = path.join("wasmopticon", "php/php-testserver");
21+
const rootPackageDir = path.join(
22+
projectRoot,
23+
"wasmopticon",
24+
"php",
25+
"php-testserver",
26+
);
2127
const dir = await copyPackageAnonymous(rootPackageDir);
2228

2329
const app: AppDefinition = {
@@ -74,7 +80,12 @@ test("app-volumes", async () => {
7480
test("volume-mount-inside-package-dir", async () => {
7581
const env = TestEnv.fromEnv();
7682

77-
const rootPackageDir = path.join("wasmopticon", "php/php-testserver");
83+
const rootPackageDir = path.join(
84+
projectRoot,
85+
"wasmopticon",
86+
"php",
87+
"php-testserver",
88+
);
7889
const dir = await copyPackageAnonymous(rootPackageDir);
7990

8091
// The PHP testserver mounts code at /app, so we'll mount a volume inside that.

tests/job/job.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from "node:fs";
2+
import path from "node:path";
23

34
import {
45
AppJob,
@@ -8,6 +9,7 @@ import {
89
TestEnv,
910
} from "../../src/index";
1011
import { LogSniff } from "../../src/log";
12+
import { projectRoot } from "../utils/path";
1113

1214
const SECOND = 1000;
1315

@@ -21,7 +23,7 @@ async function performTest(
2123
const env = TestEnv.fromEnv();
2224
const appName = randomAppName();
2325

24-
const filePath = "./fixtures/php/path-logger.php";
26+
const filePath = path.join(projectRoot, "fixtures", "php", "path-logger.php");
2527
const phpPathLogger = await fs.promises.readFile(filePath, "utf-8");
2628

2729
const spec = buildPhpApp(phpPathLogger, { name: appName });

tests/superpanics/python.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { buildPythonApp, TestEnv } from "../../src/index";
22
import * as fs from "node:fs";
3+
import path from "node:path";
4+
import { projectRoot } from "../utils/path";
35

46
const AM_TRIES = 2;
57
// Test that we can deploy a simple python app
@@ -9,12 +11,12 @@ test.concurrent("deploy python app", async () => {
911
i++;
1012
try {
1113
const env = TestEnv.fromEnv();
12-
const filePath = "./fixtures/python/echo-server.py";
14+
const filePath = path.join(projectRoot, "fixtures", "python", "echo-server.py");
1315
let testCode = await fs.promises.readFile(filePath, "utf-8");
1416
testCode = testCode.replaceAll("__TEMPLATE__", `${Math.random()}`);
1517
console.log(testCode);
1618
const app = buildPythonApp(testCode);
17-
const appInfo = await env.deployApp(app);
19+
const appInfo = await env.deployApp(app, { noWait: true });
1820

1921
const uniquePing = Math.random();
2022
const want = `${uniquePing}`;

tests/utils/path.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import path from "node:path";
2+
3+
// Jest runs with cwd at the project root; keep it simple and stable.
4+
export const projectRoot = path.resolve(process.cwd());

tests/validation/log.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from "fs/promises";
2+
import path from "node:path";
23
import {
34
randomAppName,
45
buildPhpApp,
@@ -7,10 +8,11 @@ import {
78
TestEnv,
89
} from "../../src";
910
import { countSubstrings } from "../../src/log";
11+
import { projectRoot } from "../utils/path";
1012

1113
describe("Log tests", () => {
1214
it("Check fetch is logged on simple logging app", async () => {
13-
const filePath = "./fixtures/php/path-logger.php";
15+
const filePath = path.join(projectRoot, "fixtures", "php", "path-logger.php");
1416
const phpPathLogger = await fs.readFile(filePath, "utf-8");
1517
const env = TestEnv.fromEnv();
1618
const appName = randomAppName();
@@ -19,7 +21,7 @@ describe("Log tests", () => {
1921
const spec = buildPhpApp(phpPathLogger, { name: appName });
2022
spec.appYaml.name = appName;
2123
console.log(JSON.stringify(spec, null, " "));
22-
const deployedApp = await env.deployApp(spec);
24+
const deployedApp = await env.deployApp(spec, { noWait: true });
2325
await env.fetchApp(deployedApp, "/this-is-a-unique-path");
2426

2527
// Check logs

0 commit comments

Comments
 (0)