From bfa78886e5b7c471c3fed46d6365e4cff7fa3071 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 10 Sep 2024 03:06:20 +0300 Subject: [PATCH] add tests and improve lint --- .eslintrc.json | 47 +++++++- .github/workflows/ci-examples.yml | 8 +- .github/workflows/ci.yml | 3 +- testing/test-setup/.eslintrc.json | 12 ++ testing/test-setup/README.md | 16 +++ testing/test-setup/project.json | 16 +++ testing/test-setup/src/lib/console.mock.ts | 29 +++++ testing/test-setup/src/lib/fs.mock.ts | 21 ++++ testing/test-setup/src/lib/reset.mock.ts | 7 ++ testing/test-setup/tsconfig.json | 19 ++++ testing/test-setup/tsconfig.lib.json | 10 ++ .../test-utils/mock/execute-process.mock.mjs | 36 ++++++ testing/test-utils/project.json | 2 +- testing/test-utils/src/index.ts | 3 + testing/test-utils/src/lib/constants.ts | 1 + .../src/lib/execute-process-helper.mock.ts | 22 ++++ .../test-utils/src/lib/test-folder.setup.ts | 14 +++ tooling/build-env/package.json | 4 +- tooling/build-env/project.json | 2 +- .../utils/execute-process.unit-test.ts | 104 ++++++++++++++++++ .../src/internal/utils/logging.spec.ts | 28 +++++ .../build-env/src/internal/utils/npm.spec.ts | 52 +++++++++ tooling/build-env/src/internal/utils/npm.ts | 2 +- tooling/build-env/src/shared/setup.spec.ts | 2 +- tooling/build-env/tsconfig.lib.json | 6 +- tooling/build-env/tsconfig.spec.json | 3 + tooling/tools-utils/vite.config.ts | 5 + tsconfig.base.json | 1 + 28 files changed, 461 insertions(+), 14 deletions(-) create mode 100644 testing/test-setup/.eslintrc.json create mode 100644 testing/test-setup/README.md create mode 100644 testing/test-setup/project.json create mode 100644 testing/test-setup/src/lib/console.mock.ts create mode 100644 testing/test-setup/src/lib/fs.mock.ts create mode 100644 testing/test-setup/src/lib/reset.mock.ts create mode 100644 testing/test-setup/tsconfig.json create mode 100644 testing/test-setup/tsconfig.lib.json create mode 100644 testing/test-utils/mock/execute-process.mock.mjs create mode 100644 testing/test-utils/src/lib/constants.ts create mode 100644 testing/test-utils/src/lib/execute-process-helper.mock.ts create mode 100644 testing/test-utils/src/lib/test-folder.setup.ts create mode 100644 tooling/build-env/src/internal/utils/execute-process.unit-test.ts create mode 100644 tooling/build-env/src/internal/utils/logging.spec.ts create mode 100644 tooling/build-env/src/internal/utils/npm.spec.ts diff --git a/.eslintrc.json b/.eslintrc.json index 9c0af4ce..b09855a3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,11 +13,52 @@ "error", { "enforceBuildableLibDependency": true, - "allow": [], + "allow": ["tools"], "depConstraints": [ { - "sourceTag": "*", - "onlyDependOnLibsWithTags": ["*"] + "sourceTag": "scope:shared", + "onlyDependOnLibsWithTags": ["scope:shared"] + }, + { + "sourceTag": "scope:core", + "onlyDependOnLibsWithTags": ["scope:core", "scope:shared"] + }, + { + "sourceTag": "type:e2e", + "onlyDependOnLibsWithTags": [ + "type:app", + "type:feature", + "type:util", + "type:testing" + ] + }, + { + "sourceTag": "type:app", + "onlyDependOnLibsWithTags": [ + "type:feature", + "type:util", + "type:testing" + ] + }, + { + "sourceTag": "type:feature", + "onlyDependOnLibsWithTags": [ + "type:feature", + "type:util", + "type:testing" + ] + }, + { + "sourceTag": "type:util", + "onlyDependOnLibsWithTags": ["type:util", "type:testing"] + }, + { + "sourceTag": "type:testing", + "onlyDependOnLibsWithTags": ["type:util", "type:testing"] + }, + { + "sourceTag": "type:tooling", + "onlyDependOnLibsWithTags": ["type:testing"] } ] } diff --git a/.github/workflows/ci-examples.yml b/.github/workflows/ci-examples.yml index f39ee716..95e867f6 100644 --- a/.github/workflows/ci-examples.yml +++ b/.github/workflows/ci-examples.yml @@ -46,10 +46,10 @@ jobs: - name: Install dependencies run: npm i - name: pretarget E2E test project - run: npx nx run cli-e2e-pretarget:pretarget-e2e + run: npx nx run cli-e2e-pretarget:pretarget-e2e --parallel 1 - name: graph E2E test project - run: npx nx run cli-e2e-graph:graph-e2e + run: npx nx run cli-e2e-graph:graph-e2e --parallel 1 - name: env E2E test project - run: npx nx run cli-e2e-env:env-e2e + run: npx nx run cli-e2e-env:env-e2e --parallel 1 - name: Original E2E test project - run: npx nx run cli-e2e-original:original-e2e + run: npx nx run cli-e2e-original:original-e2e --parallel 1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c560bfea..5d54af32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,4 +46,5 @@ jobs: - name: Install dependencies run: npm i - name: E2E test all projects with buildable environmnets - run: npx nx run-many -t e2e --parallel 10 + # run-many is only used to trigger the e2e tasks on every PR. affected would be a real life implementation + run: npx nx run-many -t e2e --parallel 1 diff --git a/testing/test-setup/.eslintrc.json b/testing/test-setup/.eslintrc.json new file mode 100644 index 00000000..0881a0fa --- /dev/null +++ b/testing/test-setup/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "parserOptions": { + "project": ["testing/test-setup/tsconfig.*?.json"] + } + } + ] +} diff --git a/testing/test-setup/README.md b/testing/test-setup/README.md new file mode 100644 index 00000000..0c4042a1 --- /dev/null +++ b/testing/test-setup/README.md @@ -0,0 +1,16 @@ +# test-setup + +This library contains test setup. + +## Mock setup + +In this library you can find all files that can be used in `setupFiles` property of `vitest.config.(unit|integration|e2e).ts` files. Currently include: + +- [console](./src/lib/console.mock.ts) mocking +- [file system](./src/lib/fs.mock.ts) mocking +- [reset](./src/lib/reset.mock.ts) mocking + +Additionally, you may find helper functions for: + +- setting up and tearing down a [testing folder](./src/lib/test-folder.setup.ts) +- [resetting](./src/lib/reset.mocks.ts) mocks diff --git a/testing/test-setup/project.json b/testing/test-setup/project.json new file mode 100644 index 00000000..96e6f190 --- /dev/null +++ b/testing/test-setup/project.json @@ -0,0 +1,16 @@ +{ + "name": "test-setup", + "$schema": "../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "testing/test-setup/src", + "projectType": "library", + "targets": { + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["testing/test-setup/**/*.ts"] + } + } + }, + "tags": ["scope:shared", "type:testing"] +} diff --git a/testing/test-setup/src/lib/console.mock.ts b/testing/test-setup/src/lib/console.mock.ts new file mode 100644 index 00000000..dc87cc29 --- /dev/null +++ b/testing/test-setup/src/lib/console.mock.ts @@ -0,0 +1,29 @@ +import { type MockInstance, afterEach, beforeEach, vi } from 'vitest'; + +let consoleInfoSpy: MockInstance | undefined; +let consoleWarnSpy: MockInstance | undefined; +let consoleErrorSpy: MockInstance | undefined; + +beforeEach(() => { + // In multi-progress-bars, console methods are overriden + if (console.info != null) { + // eslint-disable-next-line @typescript-eslint/no-empty-function + consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); + } + + if (console.warn != null) { + // eslint-disable-next-line @typescript-eslint/no-empty-function + consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); + } + + if (console.error != null) { + // eslint-disable-next-line @typescript-eslint/no-empty-function + consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); + } +}); + +afterEach(() => { + consoleInfoSpy?.mockRestore(); + consoleWarnSpy?.mockRestore(); + consoleErrorSpy?.mockRestore(); +}); diff --git a/testing/test-setup/src/lib/fs.mock.ts b/testing/test-setup/src/lib/fs.mock.ts new file mode 100644 index 00000000..5a5f04db --- /dev/null +++ b/testing/test-setup/src/lib/fs.mock.ts @@ -0,0 +1,21 @@ +import { type MockInstance, afterEach, beforeEach, vi } from 'vitest'; +import { MEMFS_VOLUME } from '@org/test-utils'; + +vi.mock('fs', async () => { + const memfs: typeof import('memfs') = await vi.importActual('memfs'); + return memfs.fs; +}); +vi.mock('fs/promises', async () => { + const memfs: typeof import('memfs') = await vi.importActual('memfs'); + return memfs.fs.promises; +}); + +let cwdSpy: MockInstance<[], string>; + +beforeEach(() => { + cwdSpy = vi.spyOn(process, 'cwd').mockReturnValue(MEMFS_VOLUME); +}); + +afterEach(() => { + cwdSpy.mockRestore(); +}); diff --git a/testing/test-setup/src/lib/reset.mock.ts b/testing/test-setup/src/lib/reset.mock.ts new file mode 100644 index 00000000..8d66e935 --- /dev/null +++ b/testing/test-setup/src/lib/reset.mock.ts @@ -0,0 +1,7 @@ +import { vol } from 'memfs'; +import { beforeEach, vi } from 'vitest'; + +beforeEach(() => { + vi.clearAllMocks(); + vol.reset(); +}); diff --git a/testing/test-setup/tsconfig.json b/testing/test-setup/tsconfig.json new file mode 100644 index 00000000..fda68ff3 --- /dev/null +++ b/testing/test-setup/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "ESNext", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + } + ] +} diff --git a/testing/test-setup/tsconfig.lib.json b/testing/test-setup/tsconfig.lib.json new file mode 100644 index 00000000..65e232ad --- /dev/null +++ b/testing/test-setup/tsconfig.lib.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "include": ["src/**/*.ts"], + "exclude": [] +} diff --git a/testing/test-utils/mock/execute-process.mock.mjs b/testing/test-utils/mock/execute-process.mock.mjs new file mode 100644 index 00000000..3a7860db --- /dev/null +++ b/testing/test-utils/mock/execute-process.mock.mjs @@ -0,0 +1,36 @@ +const interval = parseInt(process.argv[2] || 100); +let runs = parseInt(process.argv[3] || 4); +let throwError = process.argv[4] === '1'; + +/** + * Custom runner implementation that simulates asynchronous situations. + * It logs progress to the console with a configurable interval and defaults to 100ms. + * The number of runs is also configurable and defaults to 4. + * We can decide if the process should error or complete. By default, it completes. + * + * @arg interval: number - delay between updates in ms; defaults to 100 + * @arg runs: number - number of updates; defaults to 4 + * @arg throwError: '1' | '0' - if the process completes or throws; defaults to '0' + **/ +(async () => { + console.info( + `process:start with interval: ${interval}, runs: ${runs}, throwError: ${throwError}` + ); + await new Promise((resolve) => { + const id = setInterval(() => { + if (runs === 0) { + clearInterval(id); + if (throwError) { + throw new Error('dummy-error'); + } else { + resolve('result'); + } + } else { + runs--; + console.info('process:update'); + } + }, interval); + }); + + console.info('process:complete'); +})(); diff --git a/testing/test-utils/project.json b/testing/test-utils/project.json index d7a89fab..f85422a0 100644 --- a/testing/test-utils/project.json +++ b/testing/test-utils/project.json @@ -3,7 +3,7 @@ "$schema": "../../node_modules/nx/schemas/project-schema.json", "sourceRoot": "projects/test-utils/src", "projectType": "library", - "tags": ["scope:utils", "type:testing-util"], + "tags": ["scope:shared", "type:testing"], "targets": { "build": { "executor": "@nx/esbuild:esbuild", diff --git a/testing/test-utils/src/index.ts b/testing/test-utils/src/index.ts index 642384f5..631711d5 100644 --- a/testing/test-utils/src/index.ts +++ b/testing/test-utils/src/index.ts @@ -1,3 +1,6 @@ export * from './lib/execute-process'; export * from './lib/terminal-command'; export * from './lib/setup'; +export * from './lib/execute-process-helper.mock'; +export * from './lib/test-folder.setup'; +export * from './lib/constants'; diff --git a/testing/test-utils/src/lib/constants.ts b/testing/test-utils/src/lib/constants.ts new file mode 100644 index 00000000..e6d5cd04 --- /dev/null +++ b/testing/test-utils/src/lib/constants.ts @@ -0,0 +1 @@ +export const MEMFS_VOLUME = '/test'; diff --git a/testing/test-utils/src/lib/execute-process-helper.mock.ts b/testing/test-utils/src/lib/execute-process-helper.mock.ts new file mode 100644 index 00000000..bc46d030 --- /dev/null +++ b/testing/test-utils/src/lib/execute-process-helper.mock.ts @@ -0,0 +1,22 @@ +import { join } from 'path'; + +const asyncProcessPath = join(__dirname, '../../mock/execute-process.mock.mjs'); + +/** + * Helps to get an async process runner config for testing. + * + * @param cfg can contain up to three properties for the async process runner + */ +export function getAsyncProcessRunnerConfig(cfg?: { + throwError?: boolean; + interval?: number; + runs?: number; +}) { + const args = [ + asyncProcessPath, + cfg?.interval ? cfg.interval + '' : '100', + cfg?.runs ? cfg.runs + '' : '4', + cfg?.throwError ? '1' : '0', + ]; + return { command: 'node', args }; +} diff --git a/testing/test-utils/src/lib/test-folder.setup.ts b/testing/test-utils/src/lib/test-folder.setup.ts new file mode 100644 index 00000000..50c7feb3 --- /dev/null +++ b/testing/test-utils/src/lib/test-folder.setup.ts @@ -0,0 +1,14 @@ +import { mkdir, rm } from 'node:fs/promises'; + +export async function setupTestFolder(dirName: string) { + await mkdir(dirName, { recursive: true }); +} + +export async function cleanTestFolder(dirName: string) { + await rm(dirName, { recursive: true, force: true }); + await mkdir(dirName, { recursive: true }); +} + +export async function teardownTestFolder(dirName: string) { + await rm(dirName, { recursive: true, force: true }); +} diff --git a/tooling/build-env/package.json b/tooling/build-env/package.json index 3b4164d4..defeb76d 100644 --- a/tooling/build-env/package.json +++ b/tooling/build-env/package.json @@ -8,7 +8,9 @@ "vite": "~5.0.0", "@nx/vite": "18.2.4", "tslib": "^2.3.0", - "nx": "18.2.4" + "nx": "18.2.4", + "vitest": "^1.3.1", + "test-utils": "*" }, "type": "commonjs", "main": "./src/index.js", diff --git a/tooling/build-env/project.json b/tooling/build-env/project.json index 5863a823..23163b53 100644 --- a/tooling/build-env/project.json +++ b/tooling/build-env/project.json @@ -48,5 +48,5 @@ } } }, - "tags": ["scope:tooling"] + "tags": ["scope:shared", "type:tooling"] } diff --git a/tooling/build-env/src/internal/utils/execute-process.unit-test.ts b/tooling/build-env/src/internal/utils/execute-process.unit-test.ts new file mode 100644 index 00000000..2d5cd37e --- /dev/null +++ b/tooling/build-env/src/internal/utils/execute-process.unit-test.ts @@ -0,0 +1,104 @@ +import { ChildProcess } from 'node:child_process'; +import { describe, expect, it, vi, beforeEach } from 'vitest'; +import { getAsyncProcessRunnerConfig } from '@org/test-utils'; +import { type ProcessObserver, executeProcess } from './execute-process'; + +describe('executeProcess', () => { + const spyObserver: ProcessObserver = { + onStdout: vi.fn(), + onStderr: vi.fn(), + onError: vi.fn(), + onComplete: vi.fn(), + }; + const errorSpy = vi.fn(); + + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('should work with node command `node -v`', async () => { + const processResult = await executeProcess({ + command: `node`, + args: ['-v'], + observer: spyObserver, + }); + + // Note: called once or twice depending on environment (2nd time for a new line) + expect(spyObserver.onStdout).toHaveBeenCalled(); + expect(spyObserver.onComplete).toHaveBeenCalledOnce(); + expect(spyObserver.onError).not.toHaveBeenCalled(); + expect(processResult.stdout).toMatch(/v\d{1,2}(\.\d{1,2}){0,2}/); + }); + + it('should work with npx command `npx --help`', async () => { + const processResult = await executeProcess({ + command: `npx`, + args: ['--help'], + observer: spyObserver, + }); + expect(spyObserver.onStdout).toHaveBeenCalledOnce(); + expect(spyObserver.onComplete).toHaveBeenCalledOnce(); + expect(spyObserver.onError).not.toHaveBeenCalled(); + expect(processResult.stdout).toContain('npm exec'); + }); + + it('should work with script `node custom-script.js`', async () => { + const processResult = await executeProcess({ + ...getAsyncProcessRunnerConfig({ interval: 10, runs: 4 }), + observer: spyObserver, + }).catch(errorSpy); + + expect(errorSpy).not.toHaveBeenCalled(); + expect(processResult.stdout).toContain('process:complete'); + expect(spyObserver.onStdout).toHaveBeenCalledTimes(6); // intro + 4 runs + complete + expect(spyObserver.onError).not.toHaveBeenCalled(); + expect(spyObserver.onComplete).toHaveBeenCalledOnce(); + }); + + it('should work with async script `node custom-script.js` that throws an error', async () => { + const processResult = await executeProcess({ + ...getAsyncProcessRunnerConfig({ + interval: 10, + runs: 1, + throwError: true, + }), + observer: spyObserver, + }).catch(errorSpy); + + expect(errorSpy).toHaveBeenCalledOnce(); + expect(processResult).toBeUndefined(); + expect(spyObserver.onStdout).toHaveBeenCalledTimes(2); // intro + 1 run before error + expect(spyObserver.onStdout).toHaveBeenLastCalledWith( + 'process:update\n', + expect.any(ChildProcess) + ); + expect(spyObserver.onStderr).toHaveBeenCalled(); + expect(spyObserver.onStderr).toHaveBeenCalledWith( + expect.stringContaining('dummy-error'), + expect.any(ChildProcess) + ); + expect(spyObserver.onError).toHaveBeenCalledOnce(); + expect(spyObserver.onComplete).not.toHaveBeenCalled(); + }); + + it('should successfully exit process after an error is thrown when ignoreExitCode is set', async () => { + const processResult = await executeProcess({ + ...getAsyncProcessRunnerConfig({ + interval: 10, + runs: 1, + throwError: true, + }), + observer: spyObserver, + ignoreExitCode: true, + }).catch(errorSpy); + + expect(errorSpy).not.toHaveBeenCalled(); + expect(processResult.code).toBe(1); + expect(processResult.stdout).toContain('process:update'); + expect(processResult.stderr).toContain('dummy-error'); + expect(spyObserver.onStdout).toHaveBeenCalledTimes(2); // intro + 1 run before error + expect(spyObserver.onStderr).toHaveBeenCalled(); + expect(spyObserver.onError).not.toHaveBeenCalled(); + expect(spyObserver.onComplete).toHaveBeenCalledOnce(); + }); +}); diff --git a/tooling/build-env/src/internal/utils/logging.spec.ts b/tooling/build-env/src/internal/utils/logging.spec.ts new file mode 100644 index 00000000..233d226b --- /dev/null +++ b/tooling/build-env/src/internal/utils/logging.spec.ts @@ -0,0 +1,28 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { error, info } from './logging'; +import { bold, gray, red } from 'ansis'; + +describe('info', () => { + let consoleInfoSpy; + let consoleErrorSpy; + beforeEach(() => { + consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(vi.fn()); + consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(vi.fn()); + }); + + it('should log info', () => { + info('message', 'token'); + expect(consoleInfoSpy).toHaveBeenCalledTimes(1); + expect(consoleInfoSpy).toHaveBeenCalledWith( + `${gray('>')} ${gray(bold('token'))} ${'message'}` + ); + }); + + it('should log error', () => { + error('message', 'token'); + expect(consoleErrorSpy).toHaveBeenCalledTimes(1); + expect(consoleErrorSpy).toHaveBeenCalledWith( + `${red('>')} ${red(bold('token'))} ${'message'}` + ); + }); +}); diff --git a/tooling/build-env/src/internal/utils/npm.spec.ts b/tooling/build-env/src/internal/utils/npm.spec.ts new file mode 100644 index 00000000..0567106a --- /dev/null +++ b/tooling/build-env/src/internal/utils/npm.spec.ts @@ -0,0 +1,52 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { logInfo, logError, setupNpmWorkspace } from './npm'; +import { bold, gray, red } from 'ansis'; +import { MEMFS_VOLUME } from '@org/test-utils'; + +describe('logInfo', () => { + let consoleInfoSpy; + beforeEach(() => { + consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(vi.fn()); + }); + + it('should log info', () => { + logInfo('message'); + expect(consoleInfoSpy).toHaveBeenCalledTimes(1); + expect(consoleInfoSpy).toHaveBeenCalledWith( + `${gray('>')} ${gray(bold('Npm Env: '))} ${'message'}` + ); + }); +}); + +describe('logError', () => { + let consoleErrorSpy; + beforeEach(() => { + consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(vi.fn()); + }); + + it('should log error', () => { + logError('message'); + expect(consoleErrorSpy).toHaveBeenCalledTimes(1); + expect(consoleErrorSpy).toHaveBeenCalledWith( + `${red('>')} ${red(bold('Npm Env: '))} ${'message'}` + ); + }); +}); + +describe.skip('setupNpmWorkspace', () => { + let cwdSpy; + let chdirSpy; + + beforeEach(() => { + cwdSpy = vi.spyOn(process, 'cwd').mockReturnValue(MEMFS_VOLUME); + }); + + afterEach(() => { + cwdSpy.mockRestore(); + chdirSpy.mockRestore(); + }); + + it('should create npm workspace in given folder', () => { + setupNpmWorkspace('tmp'); + }); +}); diff --git a/tooling/build-env/src/internal/utils/npm.ts b/tooling/build-env/src/internal/utils/npm.ts index 0f3b2dac..8f2fcc2d 100644 --- a/tooling/build-env/src/internal/utils/npm.ts +++ b/tooling/build-env/src/internal/utils/npm.ts @@ -14,7 +14,7 @@ export function logError(msg: string) { export async function setupNpmWorkspace( environmentRoot: string, verbose?: boolean -) { +): Promise { if (verbose) { logInfo(`Execute: npm init in directory ${environmentRoot}`); } diff --git a/tooling/build-env/src/shared/setup.spec.ts b/tooling/build-env/src/shared/setup.spec.ts index a5b2c253..9d1b783a 100644 --- a/tooling/build-env/src/shared/setup.spec.ts +++ b/tooling/build-env/src/shared/setup.spec.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { getEnvironmentRoot, getEnvironmentsRoot } from '@org/build-env'; +import { getEnvironmentRoot, getEnvironmentsRoot } from './setup'; describe('getEnvironmentsRoot', () => { it('should return default env dir', () => { diff --git a/tooling/build-env/tsconfig.lib.json b/tooling/build-env/tsconfig.lib.json index f05cf1b2..881d01d7 100644 --- a/tooling/build-env/tsconfig.lib.json +++ b/tooling/build-env/tsconfig.lib.json @@ -10,7 +10,11 @@ "vite.config.ts", "src/**/__snapshots__/*.ts", "src/**/*.test.ts", + "src/**/*.unit-test.ts", + "src/**/*.integration-test.ts", + "src/**/*.spec.ts", "src/**/*.mock.ts", - "test/**/*.ts" + "test/**/*.ts", + "mock/**/*.ts" ] } diff --git a/tooling/build-env/tsconfig.spec.json b/tooling/build-env/tsconfig.spec.json index a2273902..89368b76 100644 --- a/tooling/build-env/tsconfig.spec.json +++ b/tooling/build-env/tsconfig.spec.json @@ -8,6 +8,9 @@ "vite.config.ts", "mock/**/*.ts", "src/**/*.test.ts", + "src/**/*.unit-test.ts", + "src/**/*.integration-test.ts", + "src/**/*.spec.ts", "src/**/*.test.tsx", "src/**/*.test.js", "src/**/*.test.jsx", diff --git a/tooling/tools-utils/vite.config.ts b/tooling/tools-utils/vite.config.ts index a94aa92f..bd7b8fda 100644 --- a/tooling/tools-utils/vite.config.ts +++ b/tooling/tools-utils/vite.config.ts @@ -19,6 +19,11 @@ export default defineConfig({ environment: 'node', include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], reporters: ['default'], + setupFiles: [ + 'testing/test-setup/src/lib/console.mock.ts', + 'testing/test-setup/src/lib/fs.mock.ts', + 'testing/test-setup/src/lib/reset.mock.ts', + ], coverage: { reportsDirectory: '../../coverage/projects/tools-utils', provider: 'v8', diff --git a/tsconfig.base.json b/tsconfig.base.json index b0f53a1d..1d4efa73 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -19,6 +19,7 @@ "@org/cli": ["projects/cli/src/index.ts"], "@org/core": ["projects/core/src/index.ts"], "@org/models": ["projects/models/src/index.ts"], + "@org/test-setup": ["testing/test-setup/src/index.ts"], "@org/test-utils": ["testing/test-utils/src/index.ts"], "@org/tools-utils": ["tooling/tools-utils/src/index.ts"], "@org/utils": ["projects/utils/src/index.ts"]