Skip to content

Commit

Permalink
wip(perf): added stubs to vitest environments
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed May 23, 2024
1 parent d17e577 commit 29b4e14
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/components/PerformanceCollector/perfParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@extras/testEnv';
import { test, expect, it, suite } from 'vitest';
import { arePerfBoundariesValid, parseRawPerf } from './perfParser';

Expand Down
1 change: 1 addition & 0 deletions core/extras/helpers.test.ts
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';

Expand Down
60 changes: 60 additions & 0 deletions core/extras/testEnv.ts
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];
});
14 changes: 14 additions & 0 deletions core/vitest.config.ts
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, "./"),
},

},
});

0 comments on commit 29b4e14

Please sign in to comment.