Skip to content

Commit

Permalink
fix(test): update regex for global matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed Feb 13, 2025
1 parent a08425d commit 1db3491
Show file tree
Hide file tree
Showing 3 changed files with 632 additions and 631 deletions.
88 changes: 43 additions & 45 deletions src/api/global.test.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
import ava from "ava"
import "../../test-sdk/config.js"
import { pathToFileURL } from "node:url"
import ava from 'ava'
import '../../test-sdk/config.js'
import { pathToFileURL } from 'node:url'

ava.serial("env should work with different params", async (t) => {
let name = "mock-env-message"
let content = `
ava.serial('env should work with different params', async (t) => {
let name = 'mock-env-message'
let content = `
await env("MOCK_ENV_MESSAGE", "Enter a value:")
`
let type = "js"
let type = 'js'

await exec(`kit new ${name} main --no-edit`, {
env: {
...process.env,
KIT_NODE_PATH: process.execPath,
KIT_MODE: type
}
})
await exec(`kit new ${name} main --no-edit`, {
env: {
...process.env,
KIT_NODE_PATH: process.execPath,
KIT_MODE: type
}
})

await appendFile(kenvPath("scripts", `${name}.js`), content)
await appendFile(kenvPath('scripts', `${name}.js`), content)

if (process.platform === "win32") {
name += ".cmd"
}
if (process.platform === 'win32') {
name += '.cmd'
}

let p = exec(`${kenvPath("bin", name)}`)
let p = exec(`${kenvPath('bin', name)}`)

p.stdin.write("Some value\n")
p.stdin.write('Some value\n')

let { stdout } = await p
let { stdout } = await p

t.regex(stdout, /env/)
t.regex(stdout, /env/)
})

ava.serial("All globals exist", async (t) => {
// TODO: Make platform independent...
/** @type {import("../platform/darwin")} */
await import(pathToFileURL(kitPath("core", "utils.js")).href)
await import(pathToFileURL(kitPath("platform", "darwin.js")).href)
await import(pathToFileURL(kitPath("target", "app.js")).href)
await import(pathToFileURL(kitPath("api", "pro.js")).href)
await import(pathToFileURL(kitPath("index.js")).href)

let files = await readdir(kitPath("types"))
let content = ``
for await (let f of files) {
content += await readFile(kitPath("types", f), "utf-8")
}

let matches = content
.match(/(?<=var ).*?(?=:)/gim)
.filter((m) => !m.includes("projectPath"))

for (let m of matches) {
t.log(`Checking if ${m} exists on global...`)
t.true(typeof global[m] !== "undefined", `${m} is missing`)
}
ava.serial('All globals exist', async (t) => {
// TODO: Make platform independent...
/** @type {import("../platform/darwin")} */
await import(pathToFileURL(kitPath('core', 'utils.js')).href)
await import(pathToFileURL(kitPath('platform', 'darwin.js')).href)
await import(pathToFileURL(kitPath('target', 'app.js')).href)
await import(pathToFileURL(kitPath('api', 'pro.js')).href)
await import(pathToFileURL(kitPath('index.js')).href)

let files = await readdir(kitPath('types'))
let content = ``
for await (let f of files) {
content += await readFile(kitPath('types', f), 'utf-8')
}

let matches = content.match(/(?<=^\s*var ).*?(?=:)/gim).filter((m) => !m.includes('projectPath'))

for (let m of matches) {
t.log(`Checking if ${m} exists on global...`)
t.true(typeof global[m] !== 'undefined', `${m} is missing`)
}
})
Loading

0 comments on commit 1db3491

Please sign in to comment.