Skip to content

Commit 4109b87

Browse files
committed
tests
1 parent 9a5e9a0 commit 4109b87

6 files changed

Lines changed: 76 additions & 43 deletions

File tree

.config/pnpm/rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
lockfile=false
22
resolution-mode=time-based
33
store-dir=/home/dev/.local/share/pnpm/store
4+
global-bin-dir=/home/dev/.local/bin

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"dependencies": {
1717
"@commander-js/extra-typings": "^14.0.0",
18+
"@devcontainers/cli": "^0.80.1",
1819
"@eslint/js": "^9.39.1",
1920
"@prettier/plugin-xml": "^3.4.2",
2021
"@tsconfig/node24": "^24.0.1",

scripts/installPackage.ts

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,3 @@
1-
import { cp, mkdir, rm, writeFile } from "node:fs/promises";
2-
import path from "node:path";
1+
import { installPackage } from "@/scripts/tasks/installPackage.js";
32

4-
import { $ } from "execa";
5-
6-
import { packageOutputPath, packagePrefix } from "@/scripts/project.js";
7-
import { build } from "@/scripts/tasks/build.js";
8-
import pkg from "@/setup/package.json" with { type: "json" };
9-
10-
const XDG_DATA_HOME = process.env.XDG_DATA_HOME;
11-
if (!XDG_DATA_HOME) {
12-
throw new Error("XDG_DATA_HOME is not set.");
13-
}
14-
15-
await build();
16-
17-
// Copy the dist folder to a temporary location
18-
const packageName = `${packagePrefix}${pkg.name}`;
19-
const tempPath = `/tmp/${packageName}`;
20-
await rm(tempPath, { recursive: true, force: true });
21-
await mkdir(tempPath, { recursive: true });
22-
await cp(packageOutputPath, tempPath, { recursive: true });
23-
await writeFile(path.resolve(tempPath, "pnpm-workspace.yaml"), "");
24-
await writeFile(
25-
path.resolve(tempPath, ".npmrc"),
26-
[
27-
"lockfile=false",
28-
"resolution-mode=time-based",
29-
"shared-workspace-lockfile=false",
30-
"inject-workspace-packages=true",
31-
].join("\n"),
32-
);
33-
34-
// Install the package globally after pnpm deploy.
35-
process.env.NODE_ENV = "production";
36-
const installPath = path.resolve(XDG_DATA_HOME, pkg.name);
37-
await rm(installPath, { recursive: true, force: true });
38-
const $$ = $({ stdio: "inherit", verbose: "full", cwd: tempPath });
39-
await $$`pnpm install`;
40-
await $$`pnpm deploy --filter=${packageName} --prod ${installPath}`;
41-
await $$`npm uninstall --global ${packageName}`;
42-
await $$`npm install --global ${installPath}`;
43-
await $$`rm --recursive ${tempPath}`;
3+
await installPackage();

scripts/tasks/installPackage.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { cp, mkdir, rm, writeFile } from "node:fs/promises";
2+
import path from "node:path";
3+
4+
import { $ } from "execa";
5+
6+
import { packageOutputPath, packagePrefix } from "@/scripts/project.js";
7+
import { build } from "@/scripts/tasks/build.js";
8+
import pkg from "@/setup/package.json" with { type: "json" };
9+
10+
export const installPackage = async () => {
11+
const XDG_DATA_HOME = process.env.XDG_DATA_HOME;
12+
if (!XDG_DATA_HOME) {
13+
throw new Error("XDG_DATA_HOME is not set.");
14+
}
15+
16+
await build();
17+
18+
// Copy the dist folder to a temporary location
19+
const packageName = `${packagePrefix}${pkg.name}`;
20+
const tempPath = `/tmp/${packageName}`;
21+
await rm(tempPath, { recursive: true, force: true });
22+
await mkdir(tempPath, { recursive: true });
23+
await cp(packageOutputPath, tempPath, { recursive: true });
24+
await writeFile(path.resolve(tempPath, "pnpm-workspace.yaml"), "");
25+
await writeFile(
26+
path.resolve(tempPath, ".npmrc"),
27+
[
28+
"lockfile=false",
29+
"resolution-mode=time-based",
30+
"shared-workspace-lockfile=false",
31+
"inject-workspace-packages=true",
32+
].join("\n"),
33+
);
34+
35+
// Install the package globally after pnpm deploy.
36+
process.env.NODE_ENV = "production";
37+
const installPath = path.resolve(XDG_DATA_HOME, pkg.name);
38+
await rm(installPath, { recursive: true, force: true });
39+
const $$ = $({ stdio: "inherit", verbose: "full", cwd: tempPath });
40+
await $$`pnpm install`;
41+
await $$`pnpm deploy --filter=${packageName} --prod ${installPath}`;
42+
await $$({ reject: false })`pnpm uninstall --silent --global ${packageName}`;
43+
await $$`pnpm install --global ${installPath}`;
44+
await $$`rm --recursive ${tempPath}`;
45+
};

scripts/test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
console.log("TODO");
1+
import { mkdir, rm } from "node:fs/promises";
2+
3+
import { $ } from "execa";
4+
5+
import { packagePrefix } from "@/scripts/project.js";
6+
import { installPackage } from "@/scripts/tasks/installPackage.js";
7+
8+
await installPackage();
9+
10+
const tempPath = `/tmp/${packagePrefix}/tests`;
11+
const $$ = $({ stdio: "inherit", verbose: "full", cwd: tempPath });
12+
13+
const reset = async (path: string) => {
14+
await rm(path, { recursive: true, force: true });
15+
await mkdir(path, { recursive: true });
16+
};
17+
18+
await reset(tempPath);
19+
await $$`create-devcontainer csharp`;
20+
await $$`devcontainer up --remove-existing-container --workspace-folder ${tempPath}`;
21+
await $$`devcontainer exec --workspace-folder ${tempPath} pnpm lint`;
22+
23+
await reset(tempPath);
24+
await $$`create-devcontainer typescript`;
25+
await $$`devcontainer up --remove-existing-container --workspace-folder ${tempPath}`;
26+
await $$`devcontainer exec --workspace-folder ${tempPath} pnpm lint`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
lockfile=false
22
resolution-mode=time-based
33
store-dir=/home/${remoteUser}/.local/share/pnpm/store
4+
global-bin-dir=/home/${remoteUser}/.local/bin

0 commit comments

Comments
 (0)