Skip to content

Commit 78cab88

Browse files
committed
fix: enable running tests without building
1 parent 6feb129 commit 78cab88

15 files changed

+129
-137
lines changed

package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"scripts": {
99
"@ci:build": "npm run build",
1010
"@ci:lint": "eslint --format unix . && prettier . --check --with-node-modules --log-level=warn",
11-
"@ci:release": "npm run build && changeset publish && npm ci",
11+
"@ci:release": "npm run build && node scripts/pkg-toggle && changeset publish && node scripts/pkg-toggle && npm ci",
1212
"@ci:test": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" MARKO_DEBUG=1 c8 npm test",
1313
"@ci:version": "npm run build && npm run format && changeset version && npm i --package-lock-only",
14-
"build": "npm run build -w packages -w packages/adapters",
14+
"build": "npm run build -w packages -w packages/adapters --if-present",
1515
"build:examples": "npm run build -w examples",
1616
"change": "changeset add",
1717
"format": "eslint --format unix --fix .; prettier . --write --with-node-modules --log-level=warn",

packages/explorer/lib/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export declare function start(port: number): Promise<{
2+
port: number;
3+
close(): Promise<void>;
4+
}>;

packages/explorer/index.ts packages/explorer/lib/index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2-
// @ts-ignore-next-line - Errors during build due to missing types?
31
import { spawnServerWorker } from "@marko/run/vite";
42
import path from "path";
53
import { fileURLToPath } from "url";
64

75
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8-
96
const entry = path.join(__dirname, "server.js");
107

11-
export async function start(port: number) {
8+
export async function start(port) {
129
const worker = await spawnServerWorker(entry, [], port, undefined, false);
1310
return {
1411
port,

packages/explorer/server.ts packages/explorer/lib/server.js

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { exec } from "child_process";
22
import compression from "compression";
33
import { createServer } from "http";
4-
import { IncomingMessage } from "http";
5-
import { ServerResponse } from "http";
64
import { dirname } from "path";
75
import path from "path";
86
import createStaticServe from "serve-static";
@@ -15,9 +13,9 @@ const packageDir = path.join(__dirname, "..");
1513
const appDir = path.join(packageDir, ".app");
1614
const entryFile = path.join(packageDir, "src", "index.ts");
1715

18-
let buildPromise: Promise<void> | null = null;
16+
let buildPromise = null;
1917
async function build() {
20-
return (buildPromise ??= new Promise<void>((resolve, reject) => {
18+
return (buildPromise ??= new Promise((resolve, reject) => {
2119
exec(
2220
`marko-run build --output ${appDir} ${entryFile}`,
2321
{ cwd: packageDir, env: { ...process.env, MR_EXPLORER: "false" } },
@@ -34,22 +32,38 @@ async function build() {
3432
}));
3533
}
3634

37-
let middleware = (req: IncomingMessage, res: ServerResponse) => {
35+
let middleware = (req, res) => {
3836
build().then(() => middleware(req, res));
3937
};
4038

4139
const compress = compression({
4240
flush: zlib.constants.Z_PARTIAL_FLUSH,
4341
threshold: 500,
4442
});
45-
const staticServe = createStaticServe(appDir, {
43+
const servePublic = createStaticServe(`${appDir}/public`, {
4644
index: false,
45+
redirect: false,
46+
maxAge: "10 minutes",
47+
});
48+
49+
const serveAssets = createStaticServe(`${appDir}/public/assets`, {
50+
index: false,
51+
redirect: false,
4752
immutable: true,
53+
fallthrough: false,
4854
maxAge: "365 days",
4955
});
5056

5157
createServer((req, res) =>
52-
compress(req as any, res as any, () =>
53-
staticServe(req, res, () => middleware(req, res)),
54-
),
58+
compress(req, res, () => {
59+
if (req.url.startsWith("/assets/")) {
60+
req.url = req.url.slice(7);
61+
serveAssets(req, res, () => {
62+
res.statusCode = 404;
63+
res.end();
64+
});
65+
} else {
66+
servePublic(req, res, () => middleware(req, res));
67+
}
68+
}),
5569
).listen(PORT);

packages/explorer/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@
1515
"type": "module",
1616
"exports": {
1717
".": {
18-
"import": "./dist/index.js",
19-
"require": "./dist/index.cjs"
18+
"import": "./lib/index.js",
19+
"types": "./lib/index.d.ts"
2020
}
2121
},
22-
"main": "dist/index.cjs",
2322
"files": [
2423
"dist",
2524
"src"
2625
],
2726
"scripts": {
28-
"build": "tsc -b tsconfig.build.json && tsx scripts/build.ts",
2927
"dev": "MR_EXPLORER=false marko-run",
3028
"preview": "MR_EXPLORER=false marko-run preview"
3129
},
@@ -42,6 +40,9 @@
4240
"typescript": "^5.7.2",
4341
"vite": "^6.0.0"
4442
},
43+
"peerDependencies": {
44+
"@marko/run": "^0"
45+
},
4546
"logo": {
4647
"url": "https://github.com/marko-js/run/raw/main/assets/marko-run.png"
4748
}

packages/explorer/scripts/build.ts

-50
This file was deleted.

packages/explorer/scripts/importMetaURL.js

-2
This file was deleted.

packages/explorer/tsconfig.build.json

-8
This file was deleted.

packages/explorer/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"strict": true,
44
"target": "es6",
55
"module": "esnext",
6-
"moduleResolution": "node",
6+
"moduleResolution": "bundler",
77
"allowSyntheticDefaultImports": true,
88
"resolveJsonModule": true,
99
"lib": ["es2018", "dom"]

packages/run/package.json

+9-53
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,14 @@
1414
"author": "Ryan Turnquist <rturnq@gmail.com>",
1515
"type": "module",
1616
"exports": {
17-
".": {
18-
"types": "./dist/runtime/index.d.ts",
19-
"import": "./dist/runtime/index.js",
20-
"require": "./dist/runtime/index.cjs"
21-
},
22-
"./namespace": {
23-
"types": "./dist/runtime/namespace.d.ts"
24-
},
25-
"./router": {
26-
"types": "./dist/runtime/router.d.ts",
27-
"import": "./dist/runtime/router.js",
28-
"require": "./dist/runtime/router.cjs"
29-
},
30-
"./vite": {
31-
"types": "./dist/vite/index.d.ts",
32-
"import": "./dist/vite/index.js",
33-
"require": "./dist/vite/index.cjs"
34-
},
35-
"./adapter/middleware": {
36-
"types": "./dist/adapter/middleware.d.ts",
37-
"import": "./dist/adapter/middleware.js",
38-
"require": "./dist/adapter/middleware.cjs"
39-
},
40-
"./adapter": {
41-
"types": "./dist/adapter/index.d.ts",
42-
"import": "./dist/adapter/index.js",
43-
"require": "./dist/adapter/index.cjs"
44-
}
45-
},
46-
"main": "./src/runtime/index.ts",
47-
"types": "./dist/runtime/index.d.ts",
48-
"typesVersions": {
49-
"*": {
50-
"*": [
51-
"./dist/runtime/index.d.ts"
52-
],
53-
"namespace": [
54-
"./dist/runtime/namespace.d.ts"
55-
],
56-
"router": [
57-
"./dist/runtime/router.d.ts"
58-
],
59-
"vite": [
60-
"./dist/vite/index.d.ts"
61-
],
62-
"adapter/middleware": [
63-
"./dist/adapter/middleware.d.ts"
64-
],
65-
"adapter": [
66-
"./dist/adapter/index.d.ts"
67-
]
68-
}
17+
".": "./src/runtime/index.ts",
18+
"./namespace": "./src/runtime/namespace.ts",
19+
"./router": "./src/runtime/router.ts",
20+
"./vite": "./src/vite/index.ts",
21+
"./adapter/middleware": "./src/adapter/middleware.ts",
22+
"./adapter": "./src/adapter/index.ts"
6923
},
24+
"types": "./src/runtime/index.ts",
7025
"bin": {
7126
"marko-run": "./dist/cli/index.mjs"
7227
},
@@ -75,7 +30,7 @@
7530
],
7631
"scripts": {
7732
"build": "rm -rf ./dist && tsc -b && tsx scripts/build.ts",
78-
"test": "cross-env NODE_ENV=test mocha \"./src/**/__tests__/*.test.?(c)ts\"",
33+
"test": "cross-env NODE_ENV=test NODE_OPTIONS='$NODE_OPTIONS --import tsx' mocha \"./src/**/__tests__/*.test.?(c)ts\"",
7934
"test:inspect": "npm test -- --inspect",
8035
"test:update": "npm test -- --update",
8136
"test:watch": "npm test -- --watch"
@@ -106,6 +61,7 @@
10661
"@marko/fixture-snapshots": "^2.2.1",
10762
"@marko/testing-library": "^6.2.0",
10863
"@types/debug": "^4.1.12",
64+
"@types/diff": "^7.0.0",
10965
"@types/glob": "^8.1.0",
11066
"@types/human-format": "^1.0.3",
11167
"@types/jsdom": "^21.1.7",

packages/run/package.toggle.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"exports": {
3+
".": {
4+
"types": "./dist/runtime/index.d.ts",
5+
"import": "./dist/runtime/index.js",
6+
"require": "./dist/runtime/index.cjs"
7+
},
8+
"./namespace": {
9+
"types": "./dist/runtime/namespace.d.ts"
10+
},
11+
"./router": {
12+
"types": "./dist/runtime/router.d.ts",
13+
"import": "./dist/runtime/router.js",
14+
"require": "./dist/runtime/router.cjs"
15+
},
16+
"./vite": {
17+
"types": "./dist/vite/index.d.ts",
18+
"import": "./dist/vite/index.js",
19+
"require": "./dist/vite/index.cjs"
20+
},
21+
"./adapter/middleware": {
22+
"types": "./dist/adapter/middleware.d.ts",
23+
"import": "./dist/adapter/middleware.js",
24+
"require": "./dist/adapter/middleware.cjs"
25+
},
26+
"./adapter": {
27+
"types": "./dist/adapter/index.d.ts",
28+
"import": "./dist/adapter/index.js",
29+
"require": "./dist/adapter/index.cjs"
30+
}
31+
},
32+
"types": "./dist/runtime/index.d.ts",
33+
"typesVersions": {
34+
"*": {
35+
"*": ["./dist/runtime/index.d.ts"],
36+
"namespace": ["./dist/runtime/namespace.d.ts"],
37+
"router": ["./dist/runtime/router.d.ts"],
38+
"vite": ["./dist/vite/index.d.ts"],
39+
"adapter/middleware": ["./dist/adapter/middleware.d.ts"],
40+
"adapter": ["./dist/adapter/index.d.ts"]
41+
}
42+
}
43+
}

packages/run/src/__tests__/main.test.cts packages/run/src/__tests__/main.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ import { defaultNormalizer, defaultSerializer } from "@marko/fixture-snapshots";
22
import { diffLines } from "diff";
33
import fs from "fs";
44
import { JSDOM } from "jsdom";
5-
// import url from 'url'
6-
import snap from "mocha-snap";
5+
import mochaSnap from "mocha-snap";
76
import { createRequire } from "module";
87
import path from "path";
98
import * as playwright from "playwright";
9+
import url from "url";
1010

1111
import * as cli from "../cli/commands";
1212
import type { Options } from "../vite";
1313
import { SpawnedServer, waitForServer } from "../vite/utils/server";
1414

15-
// const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
15+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
16+
const snap = (mochaSnap as any).default as typeof mochaSnap;
1617

1718
// https://github.com/esbuild-kit/tsx/issues/113
1819
const { toString } = Function.prototype;

0 commit comments

Comments
 (0)