Fix broken golden standard tests caused by changes to kcl-samples (#5065)
* Fix our golden standard tests (broken by new assemblies kcl-samples) * Finally use the right combination of env vars * Fix the manifest * Continue to fix multiple file kcl-samples * Fix loading in desktop app * Type narrow for tsc * fmt --------- Co-authored-by: Frank Noirot <frank@kittycad.io>
This commit is contained in:
@ -1,5 +1,21 @@
|
||||
import { isDesktop } from 'lib/isDesktop'
|
||||
|
||||
// Polyfill window.electron fs functions as needed when in a nodejs context
|
||||
// (INTENDED FOR VITEST SHINANGANS.)
|
||||
if (process.env.NODE_ENV === 'test' && process.env.VITEST) {
|
||||
const fs = require('node:fs/promises')
|
||||
const path = require('node:path')
|
||||
Object.assign(window, {
|
||||
electron: {
|
||||
readFile: fs.readFile,
|
||||
stat: fs.stat,
|
||||
readdir: fs.readdir,
|
||||
path,
|
||||
process: {},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/// FileSystemManager is a class that provides a way to read files from the local file system.
|
||||
/// It assumes that you are in a project since it is solely used by the std lib
|
||||
/// when executing code.
|
||||
@ -19,13 +35,9 @@ class FileSystemManager {
|
||||
}
|
||||
|
||||
async readFile(path: string): Promise<Uint8Array> {
|
||||
// Using local file system only works from desktop.
|
||||
if (!isDesktop()) {
|
||||
return Promise.reject(
|
||||
new Error(
|
||||
'This function can only be called from the desktop application'
|
||||
)
|
||||
)
|
||||
// Using local file system only works from desktop and nodejs
|
||||
if (!window?.electron?.readFile) {
|
||||
return Promise.reject(new Error('No polyfill found for this function'))
|
||||
}
|
||||
|
||||
return this.join(this.dir, path).then((filePath) => {
|
||||
@ -35,12 +47,8 @@ class FileSystemManager {
|
||||
|
||||
async exists(path: string): Promise<boolean | void> {
|
||||
// Using local file system only works from desktop.
|
||||
if (!isDesktop()) {
|
||||
return Promise.reject(
|
||||
new Error(
|
||||
'This function can only be called from the desktop application'
|
||||
)
|
||||
)
|
||||
if (!window?.electron?.stat) {
|
||||
return Promise.reject(new Error('No polyfill found for this function'))
|
||||
}
|
||||
|
||||
return this.join(this.dir, path).then(async (file) => {
|
||||
@ -57,12 +65,8 @@ class FileSystemManager {
|
||||
|
||||
async getAllFiles(path: string): Promise<string[] | void> {
|
||||
// Using local file system only works from desktop.
|
||||
if (!isDesktop()) {
|
||||
return Promise.reject(
|
||||
new Error(
|
||||
'This function can only be called from the desktop application'
|
||||
)
|
||||
)
|
||||
if (!window?.electron?.readdir) {
|
||||
return Promise.reject(new Error('No polyfill found for this function'))
|
||||
}
|
||||
|
||||
return this.join(this.dir, path).then((filepath) => {
|
||||
|
Reference in New Issue
Block a user