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
- Loading branch information
Showing
16 changed files
with
546 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
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, | ||
}); | ||
}); | ||
}); |
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,139 +1,122 @@ | ||
import assert from "node:assert"; | ||
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 { after, before, test } from "node:test"; | ||
import { fileURLToPath } from "node:url"; | ||
import fg from "fast-glob"; | ||
import { runBuild } from "../incremental-build.mjs"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
// copy over files from the template dir to the src dir | ||
before(() => { | ||
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}")); | ||
describe("stable 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); | ||
} | ||
}); | ||
|
||
test("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, | ||
for (const file of files) { | ||
const filePath = file.replace(templateDir, srcDir); | ||
copyFileSync(file, filePath); | ||
} | ||
}); | ||
|
||
const distFiles = fg.sync( | ||
pathJoin(__dirname, "..", "sample-workspace-dir", "dist", "**/*"), | ||
); | ||
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, | ||
}); | ||
|
||
assert.ok( | ||
distFiles.some((file) => file.includes("tsx-file.js")), | ||
"Couldn't find tsx-file.js!", | ||
); | ||
assert.ok( | ||
distFiles.some((file) => file.includes("tsx-file.d.ts")), | ||
"Couldn't find tsx-file.d.ts!", | ||
); | ||
assert.ok( | ||
distFiles.some((file) => file.includes("js-file.js")), | ||
"Couldn't find js-file.js!", | ||
); | ||
assert.ok( | ||
distFiles.some((file) => file.includes("json-file.json")), | ||
"Couldn't find json-file.json!", | ||
); | ||
assert.equal(errors.length, 0, "There were errors logged during build!"); | ||
assert.ok( | ||
logs[0].includes(`compiled: 2 files, copied 1 file`), | ||
`Log message doesn't match!\n Received: ${logs[0]}`, | ||
); | ||
}); | ||
const distFiles = fg.sync( | ||
pathJoin(__dirname, "..", "sample-workspace-dir", "dist", "**/*"), | ||
); | ||
|
||
test("It only builds changed files", async () => { | ||
const logs = []; | ||
const errors = []; | ||
const logger = { | ||
log(message) { | ||
logs.push(message); | ||
}, | ||
error(message) { | ||
errors.push(message); | ||
}, | ||
}; | ||
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"); | ||
}); | ||
|
||
// change a file | ||
const tsxFile = pathJoin( | ||
__dirname, | ||
"..", | ||
"sample-workspace-dir", | ||
"src", | ||
"tsx-file.tsx", | ||
); | ||
writeFileSync(tsxFile, `export const foo = 'bar';`); | ||
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, | ||
}); | ||
await runBuild({ | ||
rootDirectory: pathJoin(__dirname, "..", "sample-workspace-dir"), | ||
logger, | ||
}); | ||
|
||
// most important assertion, only the tsx file should have been compiled! | ||
assert.ok( | ||
logs[0].includes(`compiled: 1 file`), | ||
`Log message doesn't match!\n Received: ${logs[0]}`, | ||
); | ||
// change a file | ||
const tsxFile = pathJoin( | ||
__dirname, | ||
"..", | ||
"sample-workspace-dir", | ||
"src", | ||
"tsx-file.tsx", | ||
); | ||
writeFileSync(tsxFile, `export const foo = 'baz';`); | ||
|
||
const distFiles = fg.sync( | ||
pathJoin(__dirname, "..", "sample-workspace-dir", "dist", "**/*"), | ||
); | ||
await runBuild({ | ||
rootDirectory: pathJoin(__dirname, "..", "sample-workspace-dir"), | ||
logger, | ||
}); | ||
|
||
assert.ok( | ||
distFiles.some((file) => file.includes("tsx-file.js")), | ||
"Couldn't find tsx-file.js!", | ||
); | ||
assert.ok( | ||
distFiles.some((file) => file.includes("tsx-file.d.ts")), | ||
"Couldn't find tsx-file.d.ts!", | ||
); | ||
assert.ok( | ||
distFiles.some((file) => file.includes("js-file.js")), | ||
"Couldn't find js-file.js!", | ||
); | ||
assert.ok( | ||
distFiles.some((file) => file.includes("json-file.json")), | ||
"Couldn't find json-file.json!", | ||
); | ||
assert.equal(errors.length, 0, "There were errors logged during build!"); | ||
}); | ||
// logs[0] is the initial build | ||
// logs[1] is the initial type def build | ||
// logs[2] is the incremental rebuild | ||
// most important assertion, only the tsx file should have been compiled! | ||
expect(logs[2]).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 | ||
after(() => { | ||
const srcDir = pathJoin(__dirname, "..", "sample-workspace-dir", "src"); | ||
// 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, | ||
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.