kunkun/apps/create-kunkun/__tests__/create-template.test.ts
Huakun Shen c93ebd895e
Fix: ext window loading (#81)
* fix: extension new window loading with localStorage

* fix: extension loading in new window

* upgrade: @kksh/svelte5

* refactor: update SideBar import to Sidebar across desktop app

* fix: safely remove test directories with existsSync check

* feat: add open preference command with platform-specific shortcut

* chore: clean up vite config trailing comma
2025-01-28 04:58:54 -05:00

43 lines
1.7 KiB
TypeScript

/**
* This is a E2E test, create every template from production build and run `npm install` and `npm run build`
* When running `npm install` with bun shell, it fails in bun test environment, so I simply run everything as regular ts without test()
*/
import os from "os"
import path from "path"
import { $ } from "bun"
import { afterAll, beforeAll, describe, expect, test } from "bun:test"
import fs from "fs-extra"
import { getRootDir } from "../src/constants"
const testDir = path.join(os.tmpdir(), "kunkun-create-kunkun-test")
console.log("Test Dir: ", testDir)
const distDir = path.join(getRootDir(), "dist")
const indexjsPath = path.join(distDir, "index.mjs")
const templateNames = ["template", "react", "vue", "nuxt", "svelte", "sveltekit"]
if (fs.existsSync(testDir)) {
fs.rmdirSync(testDir, { recursive: true })
}
fs.mkdirpSync(testDir)
for (const templateName of templateNames) {
const folderName = `${templateName}-ext`
await $`node ${indexjsPath} --outdir ${testDir} --name ${folderName} --template ${templateName}`
const templateDir = path.join(testDir, folderName)
await $`rm -rf node_modules`.cwd(templateDir) // this doesn't work within bun test
await $`pnpm install`.cwd(templateDir) // this doesn't work within bun test
const out = await $`pnpm run build`.cwd(templateDir)
}
test("Build Artifact Existence", () => {
templateNames.forEach(async (templateName) => {
const expectedOutDir = templateName === "sveltekit" ? "build" : "dist"
const folderName = `${templateName}-ext`
const templateDir = path.join(testDir, folderName)
expect(fs.existsSync(path.join(templateDir, expectedOutDir))).toBeTrue()
})
})
afterAll(() => {
fs.rmdirSync(testDir, { recursive: true })
})