* WIP: Add the KCL file path into the executor * reuse the stuff that works with settings.project_directory Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes on both sides Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes on both sides Signed-off-by: Jess Frazelle <github@jessfraz.com> * helper method Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * update kcl-samples tests to not change dirs Signed-off-by: Jess Frazelle <github@jessfraz.com> * update kcl-samples tests to not change dirs Signed-off-by: Jess Frazelle <github@jessfraz.com> * fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
77 lines
2.0 KiB
TypeScript
77 lines
2.0 KiB
TypeScript
import { assertParse, initPromise, programMemoryInit } from './wasm'
|
|
import { enginelessExecutor } from '../lib/testHelpers'
|
|
|
|
import path from 'node:path'
|
|
import fs from 'node:fs/promises'
|
|
import child_process from 'node:child_process'
|
|
|
|
// The purpose of these tests is to act as a first line of defense
|
|
// if something gets real screwy with our KCL ecosystem.
|
|
// THESE TESTS ONLY RUN UNDER A NODEJS ENVIRONMENT. They DO NOT
|
|
// test under our application.
|
|
|
|
const DIR_KCL_SAMPLES = 'kcl-samples'
|
|
const URL_GIT_KCL_SAMPLES = 'https://github.com/KittyCAD/kcl-samples.git'
|
|
|
|
interface KclSampleFile {
|
|
file: string
|
|
pathFromProjectDirectoryToFirstFile: string
|
|
title: string
|
|
filename: string
|
|
description: string
|
|
}
|
|
|
|
try {
|
|
// @ts-expect-error
|
|
await fs.rm(DIR_KCL_SAMPLES, { recursive: true })
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|
|
|
|
child_process.spawnSync('git', ['clone', URL_GIT_KCL_SAMPLES, DIR_KCL_SAMPLES])
|
|
|
|
// @ts-expect-error
|
|
let files = await fs.readdir(DIR_KCL_SAMPLES)
|
|
// @ts-expect-error
|
|
const manifestJsonStr = await fs.readFile(
|
|
path.resolve(DIR_KCL_SAMPLES, 'manifest.json'),
|
|
'utf-8'
|
|
)
|
|
const manifest = JSON.parse(manifestJsonStr)
|
|
|
|
process.chdir(DIR_KCL_SAMPLES)
|
|
|
|
beforeAll(async () => {
|
|
await initPromise
|
|
})
|
|
|
|
afterAll(async () => {
|
|
try {
|
|
process.chdir('..')
|
|
await fs.rm(DIR_KCL_SAMPLES, { recursive: true })
|
|
} catch (e) {}
|
|
})
|
|
|
|
describe('Test KCL Samples from public Github repository', () => {
|
|
describe('when performing enginelessExecutor', () => {
|
|
manifest.forEach((file: KclSampleFile) => {
|
|
it(
|
|
`should execute ${file.title} (${file.file}) successfully`,
|
|
async () => {
|
|
const code = await fs.readFile(
|
|
file.pathFromProjectDirectoryToFirstFile,
|
|
'utf-8'
|
|
)
|
|
const ast = assertParse(code)
|
|
await enginelessExecutor(
|
|
ast,
|
|
programMemoryInit(),
|
|
file.pathFromProjectDirectoryToFirstFile
|
|
)
|
|
},
|
|
files.length * 1000
|
|
)
|
|
})
|
|
})
|
|
})
|