-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(perf): added stubs to vitest environments
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 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
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,3 +1,4 @@ | ||
import '@extras/testEnv'; | ||
import { test, expect } from 'vitest'; | ||
import * as helpers from './helpers'; | ||
|
||
|
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,60 @@ | ||
import path from "path"; | ||
import { vi } from "vitest"; | ||
|
||
// Stubbing env vars | ||
vi.stubEnv('TERM', 'xterm-256color'); | ||
vi.stubEnv('FORCE_COLOR', '3'); | ||
vi.stubEnv('TXADMIN_DEV_SRC_PATH', path.join(process.cwd(), '..')); | ||
vi.stubEnv('TXADMIN_DEV_VITE_URL', 'http://localhost:40122'); | ||
|
||
|
||
// Stubbing globals | ||
vi.stubGlobal('ExecuteCommand', (commandString: string) => { | ||
//noop | ||
}); | ||
vi.stubGlobal('GetConvar', (varName: string, defaultValue: string) => { | ||
if (varName === 'version') { | ||
return 'v1.0.0.9998'; | ||
} else if (varName === 'citizen_root') { | ||
return path.join(process.env.TXADMIN_DEV_FXSERVER_PATH!,); | ||
} else if (varName === 'txAdminDevMode') { | ||
return 'false'; | ||
} else if (varName === 'txAdminVerbose') { | ||
return 'false'; | ||
} else { | ||
return defaultValue; | ||
} | ||
|
||
}); | ||
vi.stubGlobal('GetCurrentResourceName', () => { | ||
return 'monitor'; | ||
}); | ||
vi.stubGlobal('GetPasswordHash', (password: string) => { | ||
return 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; | ||
}); | ||
vi.stubGlobal('GetResourceMetadata', (resourceName: string, metadataKey: string, index: number) => { | ||
if (resourceName === 'monitor' && metadataKey === 'version' && index === 0) { | ||
return 'v9.9.9'; | ||
} else { | ||
throw new Error(`not implemented`); | ||
} | ||
}); | ||
vi.stubGlobal('GetResourcePath', (resourceName: string) => { | ||
if (resourceName === 'monitor') { | ||
return path.join(__dirname, '..', '..'); | ||
} else { | ||
throw new Error(`not implemented`); | ||
} | ||
}); | ||
vi.stubGlobal('IsDuplicityVersion', () => { | ||
return true; | ||
}); | ||
vi.stubGlobal('VerifyPasswordHash', (password: string, hash: string) => { | ||
return true; | ||
}); | ||
vi.stubGlobal('ScanResourceRoot', (rootPath: string, callback: (data: object) => void) => { | ||
throw new Error(`not implemented`); | ||
}); | ||
vi.stubGlobal('Intl.getCanonicalLocales', (locales?: string | readonly string[] | undefined) => { | ||
return Array.isArray(locales) ? locales : [locales]; | ||
}); |
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,14 @@ | ||
import path from 'path'; | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
alias: { | ||
//must match the tsconfig paths | ||
"@shared": path.resolve(__dirname, "../shared"), | ||
"@extras": path.resolve(__dirname, "./extras"), | ||
"@core": path.resolve(__dirname, "./"), | ||
}, | ||
|
||
}, | ||
}); |