generated from hamlim/template-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental version for oxc-transformer usage (#15)
TODO: - ✅ Validate dev watch mode works - ✅ Experiment with JSX usage, see if we do want to expose some kind of config
- Loading branch information
Showing
20 changed files
with
609 additions
and
124 deletions.
There are no files selected for viewing
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 @@ | ||
22.8.0 |
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
119 changes: 119 additions & 0 deletions
119
packages/hohoro/__tests__/experimental-incremental-build.test.mjs
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,119 @@ | ||
import { afterEach, beforeEach, describe, expect, it } from "bun:test"; | ||
import { copyFileSync, rmSync, writeFileSync } from "node:fs"; | ||
import { dirname, join as pathJoin } from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import fg from "fast-glob"; | ||
import { runBuild } from "../experimental-incremental-build.mjs"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
describe("experimental hohoro", () => { | ||
// copy over files from the template dir to the src dir | ||
beforeEach(() => { | ||
const templateDir = pathJoin( | ||
__dirname, | ||
"..", | ||
"sample-workspace-dir", | ||
"template", | ||
); | ||
const srcDir = pathJoin(__dirname, "..", "sample-workspace-dir", "src"); | ||
const files = fg.sync(pathJoin(templateDir, "**/*.{ts,tsx,js,json}")); | ||
|
||
for (const file of files) { | ||
const filePath = file.replace(templateDir, srcDir); | ||
copyFileSync(file, filePath); | ||
} | ||
}); | ||
|
||
it("[experimental] It correctly builds the library", async () => { | ||
const logs = []; | ||
const errors = []; | ||
const logger = { | ||
log(message) { | ||
logs.push(message); | ||
}, | ||
error(message) { | ||
errors.push(message); | ||
}, | ||
}; | ||
await runBuild({ | ||
rootDirectory: pathJoin(__dirname, "..", "sample-workspace-dir"), | ||
logger, | ||
}); | ||
|
||
const distFiles = fg.sync( | ||
pathJoin(__dirname, "..", "sample-workspace-dir", "dist", "**/*"), | ||
); | ||
|
||
expect(distFiles.some((file) => file.includes("tsx-file.js"))).toBe(true); | ||
expect(distFiles.some((file) => file.includes("tsx-file.d.ts"))).toBe(true); | ||
expect(distFiles.some((file) => file.includes("js-file.js"))).toBe(true); | ||
expect(distFiles.some((file) => file.includes("json-file.json"))).toBe( | ||
true, | ||
); | ||
expect(errors.length).toBe(0); | ||
expect(logs[0]).toContain("compiled: 2 files, copied 1 file"); | ||
}); | ||
|
||
it("[experimental] It only builds changed files", async () => { | ||
const logs = []; | ||
const errors = []; | ||
const logger = { | ||
log(message) { | ||
logs.push(message); | ||
}, | ||
error(message) { | ||
errors.push(message); | ||
}, | ||
}; | ||
|
||
await runBuild({ | ||
rootDirectory: pathJoin(__dirname, "..", "sample-workspace-dir"), | ||
logger, | ||
}); | ||
|
||
// change a file | ||
const tsxFile = pathJoin( | ||
__dirname, | ||
"..", | ||
"sample-workspace-dir", | ||
"src", | ||
"tsx-file.tsx", | ||
); | ||
writeFileSync(tsxFile, `export const foo = 'bar';`); | ||
|
||
await runBuild({ | ||
rootDirectory: pathJoin(__dirname, "..", "sample-workspace-dir"), | ||
logger, | ||
}); | ||
|
||
// most important assertion, only the tsx file should have been compiled! | ||
expect(logs[1]).toContain("compiled: 1 file"); | ||
|
||
const distFiles = fg.sync( | ||
pathJoin(__dirname, "..", "sample-workspace-dir", "dist", "**/*"), | ||
); | ||
|
||
expect(distFiles.some((file) => file.includes("tsx-file.js"))).toBe(true); | ||
expect(distFiles.some((file) => file.includes("tsx-file.d.ts"))).toBe(true); | ||
expect(distFiles.some((file) => file.includes("js-file.js"))).toBe(true); | ||
expect(distFiles.some((file) => file.includes("json-file.json"))).toBe( | ||
true, | ||
); | ||
expect(errors.length).toBe(0); | ||
}); | ||
|
||
// cleanup src and dist dirs after the tests run | ||
afterEach(() => { | ||
const srcDir = pathJoin(__dirname, "..", "sample-workspace-dir", "src"); | ||
|
||
const files = fg.sync(pathJoin(srcDir, "**/*.{ts,tsx,js,json}")); | ||
for (const file of files) { | ||
rmSync(file, { recursive: true }); | ||
} | ||
rmSync(pathJoin(__dirname, "..", "sample-workspace-dir", "dist"), { | ||
recursive: true, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.