generated from hamlim/template-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup test infra - jsonc-parser is all working fine it seems
- Loading branch information
Showing
10 changed files
with
420 additions
and
30 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
packages/one-version/__fixtures__/template-monorepo/libs/pkg-a/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "pkg-a", | ||
"dependencies": { | ||
"a": "1.0.0", | ||
"b": "2.3.1", | ||
"c": "^3" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/one-version/__fixtures__/template-monorepo/libs/pkg-b/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "pkg-b", | ||
"dependencies": { | ||
"a": "1.0.0", | ||
"b": "1.2.3", | ||
"c": "^3" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/one-version/__fixtures__/template-monorepo/libs/pkg-c/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "pkg-c", | ||
"dependencies": { | ||
"a": "1.0.0", | ||
"b": "2.1.3", | ||
"c": "^3" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/one-version/__fixtures__/template-monorepo/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"workspaces": [ | ||
"libs/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,43 @@ | ||
import assert from "node:assert"; | ||
import { after, before, test } from "node:test"; | ||
import { after, before, describe, test } from "node:test"; | ||
import { parse } from "../utils/jsonc-parser.mjs"; | ||
|
||
test("parses plain old JSON fine", () => { | ||
let sample = { | ||
foo: { | ||
bar: ["baz", 1, 2, false, true, null], | ||
}, | ||
}; | ||
describe("jsonc-parser", () => { | ||
test("parses plain old JSON fine", () => { | ||
let sample = { | ||
foo: { | ||
bar: ["baz", 1, 2, false, true, null], | ||
}, | ||
}; | ||
|
||
let result = parse(JSON.stringify(sample)); | ||
let result = parse(JSON.stringify(sample)); | ||
|
||
assert.deepEqual(result, sample); | ||
assert.deepEqual(result, sample); | ||
}); | ||
|
||
test("parses JSON with comments", () => { | ||
let sample = { | ||
foo: { | ||
bar: ["baz", 1, 2, false, true, null], | ||
}, | ||
}; | ||
|
||
let result = parse(`{ | ||
// comment | ||
"foo": { | ||
"bar": [ | ||
// another comment | ||
"baz", | ||
/* block comments too */ | ||
1, | ||
2, | ||
false, | ||
true, | ||
null | ||
] | ||
} | ||
}`); | ||
|
||
assert.deepEqual(result, sample); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,167 @@ | ||
import assert from "node:assert"; | ||
import { after, before, test } from "node:test"; | ||
import { exec as execCallback } from "node:child_process"; | ||
import { promises as fsPromises } from "node:fs"; | ||
import path from "node:path"; | ||
import { after, before, describe, test } from "node:test"; | ||
import { fileURLToPath } from "node:url"; | ||
import { promisify } from "node:util"; | ||
import { start } from "../one-version.mjs"; | ||
|
||
test("supports help command", async () => { | ||
let logs = []; | ||
const logger = { | ||
log: (...args) => { | ||
logs.push(args.join(" ")); | ||
}, | ||
}; | ||
await start({ rootDirectory: process.cwd(), logger, args: ["help"] }); | ||
describe("one-version", () => { | ||
test("supports help command", async () => { | ||
let logs = []; | ||
const logger = { | ||
log: (...args) => { | ||
logs.push(args.join(" ")); | ||
}, | ||
}; | ||
await start({ rootDirectory: process.cwd(), logger, args: ["help"] }); | ||
|
||
assert.match(logs[0], /one-version/); | ||
assert.match(logs[0], /one-version/); | ||
}); | ||
}); | ||
|
||
let exec = promisify(execCallback); | ||
|
||
let __filename = fileURLToPath(import.meta.url); | ||
let __dirname = path.dirname(__filename); | ||
|
||
describe("one-version integration tests", () => { | ||
// setup | ||
// copy the `__fixtures__/template-monorepo` into the following directories | ||
// - `__fixtures__/npm` | ||
// - `__fixtures__/pnpm` | ||
// - `__fixtures__/yarn` | ||
// - `__fixtures__/yarn-berry` | ||
// - `__fixtures__/bun` | ||
// - `__fixtures__/missing` | ||
before(async () => { | ||
let fixturesDir = path.join(__dirname, "..", "__fixtures__"); | ||
let templateDir = path.join(fixturesDir, "template-monorepo"); | ||
let targetDirs = [ | ||
"npm", | ||
"pnpm", | ||
"yarn", | ||
"yarn-berry", | ||
"bun", | ||
"missing", | ||
]; | ||
|
||
async function copyDirectory(src, dest) { | ||
// Create the destination directory if it doesn't exist | ||
await fsPromises.mkdir(dest, { recursive: true }); | ||
|
||
// Read all files and subdirectories from the source directory | ||
let entries = await fsPromises.readdir(src, { withFileTypes: true }); | ||
|
||
// Copy each file and directory recursively | ||
for (let entry of entries) { | ||
let srcPath = path.join(src, entry.name); | ||
let destPath = path.join(dest, entry.name); | ||
|
||
if (entry.isDirectory()) { | ||
await copyDirectory(srcPath, destPath); | ||
} else { | ||
await fsPromises.copyFile(srcPath, destPath); | ||
} | ||
} | ||
} | ||
|
||
let lockFile = { | ||
npm: "package-lock.json", | ||
pnpm: "pnpm-lock.yaml", | ||
yarn: "yarn.lock", | ||
"yarn-berry": "yarn.lock", | ||
bun: "bun.lock", | ||
}; | ||
|
||
for (const dir of targetDirs) { | ||
const targetDir = path.join(fixturesDir, dir); | ||
try { | ||
await copyDirectory(templateDir, targetDir); | ||
if (dir !== "missing") { | ||
await fsPromises.writeFile(lockFile[dir], ""); | ||
} | ||
if (dir === "yarn-berry") { | ||
await fsPromises.writeFile(".yarnrc.yml", "nodeLinker: node-modules"); | ||
} | ||
} catch (err) { | ||
throw err; | ||
} | ||
} | ||
}); | ||
|
||
after(async () => { | ||
const fixturesDir = path.join(__dirname, "..", "__fixtures__"); | ||
const targetDirs = [ | ||
"npm", | ||
"pnpm", | ||
"yarn", | ||
"yarn-berry", | ||
"bun", | ||
"missing", | ||
]; | ||
|
||
async function removeDirectory(dir) { | ||
try { | ||
await fsPromises.rm(dir, { recursive: true, force: true }); | ||
} catch (err) { | ||
throw err; | ||
} | ||
} | ||
|
||
for (const dir of targetDirs) { | ||
const targetDir = path.join(fixturesDir, dir); | ||
await removeDirectory(targetDir); | ||
} | ||
}); | ||
|
||
test("npm", async () => { | ||
const targetDir = path.join(__dirname, "..", "__fixtures__", "npm"); | ||
await start({ rootDirectory: targetDir, logger: console }); | ||
// let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); | ||
// let versions = JSON.parse(stdout); | ||
// assert.equal(versions.length, 1); | ||
// assert.equal(versions[0].name, "one-version"); | ||
}); | ||
test("pnpm", async () => { | ||
const targetDir = path.join(__dirname, "..", "__fixtures__", "npm"); | ||
await start({ rootDirectory: targetDir, logger: console }); | ||
// let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); | ||
// let versions = JSON.parse(stdout); | ||
// assert.equal(versions.length, 1); | ||
// assert.equal(versions[0].name, "one-version"); | ||
}); | ||
test("yarn", async () => { | ||
const targetDir = path.join(__dirname, "..", "__fixtures__", "npm"); | ||
await start({ rootDirectory: targetDir, logger: console }); | ||
// let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); | ||
// let versions = JSON.parse(stdout); | ||
// assert.equal(versions.length, 1); | ||
// assert.equal(versions[0].name, "one-version"); | ||
}); | ||
test("yarn-berry", async () => { | ||
const targetDir = path.join(__dirname, "..", "__fixtures__", "npm"); | ||
await start({ rootDirectory: targetDir, logger: console }); | ||
// let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); | ||
// let versions = JSON.parse(stdout); | ||
// assert.equal(versions.length, 1); | ||
// assert.equal(versions[0].name, "one-version"); | ||
}); | ||
test("bun", async () => { | ||
const targetDir = path.join(__dirname, "..", "__fixtures__", "npm"); | ||
await start({ rootDirectory: targetDir, logger: console }); | ||
// let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); | ||
// let versions = JSON.parse(stdout); | ||
// assert.equal(versions.length, 1); | ||
// assert.equal(versions[0].name, "one-version"); | ||
}); | ||
test("missing", async () => { | ||
const targetDir = path.join(__dirname, "..", "__fixtures__", "npm"); | ||
await start({ rootDirectory: targetDir, logger: console }); | ||
// let { stdout } = await exec("npm run --silent --workspaces -- lerna version --json"); | ||
// let versions = JSON.parse(stdout); | ||
// assert.equal(versions.length, 1); | ||
// assert.equal(versions[0].name, "one-version"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function createDebug(namespace) { | ||
let enabled = process.env.DEBUG?.includes(namespace); | ||
|
||
return function debug(...args) { | ||
if (enabled) { | ||
console.log(`[${namespace}]`, ...args); | ||
} | ||
}; | ||
} |
Oops, something went wrong.