Skip to content

Commit 8d63641

Browse files
chore: add GH action workflow (#1)
* chore: add GH action workflow * chore: fix tests * chore: add pnpm in GH actions * chore: fix workflow * chore: fix tests on windows * chore: test npmrc existance
1 parent c03a580 commit 8d63641

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Node.js CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
strategy:
12+
matrix:
13+
platform: [ubuntu-latest, macos-latest, windows-latest]
14+
node-version: ["20.x"]
15+
16+
runs-on: ${{ matrix.platform }}
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
- uses: pnpm/action-setup@v3
25+
with:
26+
version: 8
27+
28+
- run: npm i
29+
- run: npm run build --if-present
30+
- run: npm test

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function prettyTime(diff: number) {
142142
}
143143

144144
export async function exec(cmd: string, args: string[], cwd: string) {
145-
const cp = spawn(cmd, args, { stdio: "inherit", cwd });
145+
const cp = spawn(cmd, args, { stdio: "inherit", cwd, shell: true });
146146

147147
return new Promise<void>((resolve) => {
148148
cp.on("exit", (code) => {

test/install.test.ts renamed to test/commands.test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as path from "path";
2+
import * as fs from "fs";
23
import { isDirectory, isFile, runJsr, withTempEnv } from "./test_utils";
34
import * as assert from "node:assert/strict";
45

56
describe("install", () => {
67
it("jsr i @std/encoding - resolve latest version", async () => {
78
await withTempEnv(["i", "@std/encoding"], async (getPkgJson, dir) => {
89
const pkgJson = await getPkgJson();
9-
assert(
10+
assert.ok(
1011
pkgJson.dependencies && "@std/encoding" in pkgJson.dependencies,
1112
"Missing dependency entry"
1213
);
@@ -17,7 +18,14 @@ describe("install", () => {
1718
);
1819

1920
const depPath = path.join(dir, "node_modules", "@std", "encoding");
20-
assert(await isDirectory(depPath), "Not installed in node_modules");
21+
assert.ok(await isDirectory(depPath), "Not installed in node_modules");
22+
23+
const npmrcPath = path.join(dir, ".npmrc");
24+
const npmRc = await fs.promises.readFile(npmrcPath, "utf-8");
25+
assert.ok(
26+
npmRc.includes("@jsr:registry=https://npm.jsr.io"),
27+
"Missing npmrc registry"
28+
);
2129
});
2230
});
2331

@@ -96,7 +104,7 @@ describe("install", () => {
96104
await withTempEnv(
97105
["i", "--npm", "@std/[email protected]"],
98106
async (_, dir) => {
99-
assert(
107+
assert.ok(
100108
await isFile(path.join(dir, "package-lock.json")),
101109
"npm lockfile not created"
102110
);
@@ -108,7 +116,7 @@ describe("install", () => {
108116
await withTempEnv(
109117
["i", "--yarn", "@std/[email protected]"],
110118
async (_, dir) => {
111-
assert(
119+
assert.ok(
112120
await isFile(path.join(dir, "yarn.lock")),
113121
"yarn lockfile not created"
114122
);
@@ -120,7 +128,7 @@ describe("install", () => {
120128
await withTempEnv(
121129
["i", "--pnpm", "@std/[email protected]"],
122130
async (_, dir) => {
123-
assert(
131+
assert.ok(
124132
await isFile(path.join(dir, "pnpm-lock.yaml")),
125133
"pnpm lockfile not created"
126134
);
@@ -140,7 +148,7 @@ describe("remove", () => {
140148
assert.equal(pkgJson.dependencies, undefined);
141149

142150
const depPath = path.join(dir, "node_modules", "@std", "encoding");
143-
assert(
151+
assert.ok(
144152
!(await isDirectory(depPath)),
145153
"Folder in node_modules not removed"
146154
);

test/test_utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export interface PkgJson {
1515

1616
export async function runJsr(args: string[], cwd: string) {
1717
const bin = path.join(__dirname, "..", "src", "bin.ts");
18-
return await exec("npx", ["ts-node", bin, ...args], cwd);
18+
const tsNode = path.join(__dirname, "..", "node_modules", ".bin", "ts-node");
19+
return await exec(tsNode, [bin, ...args], cwd);
1920
}
2021

2122
export async function withTempEnv(

0 commit comments

Comments
 (0)