Skip to content

Commit

Permalink
Merge pull request #1033 from chromaui/cody/cap-2175-fix-initial-type…
Browse files Browse the repository at this point in the history
…script-errors

Fix initial TypeScript errors
  • Loading branch information
codykaup authored Sep 11, 2024
2 parents 93e8843 + c8cf4f3 commit 253c46c
Show file tree
Hide file tree
Showing 9 changed files with 675 additions and 404 deletions.
4 changes: 4 additions & 0 deletions .codacy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
exclude_paths:
- 'CHANGELOG.md'
- 'vitest.no-threads.config.ts'
4 changes: 3 additions & 1 deletion node-src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ vi.mock('execa');
// NOTE: we'd prefer to mock the require.resolve() of `@chromatic-com/playwright/..` but
// vitest doesn't allow you to do that.
const mockedBuildCommand = 'mocked build command';
vi.mock('./lib/e2e', async (importOriginal) => ({
vi.mock(import('./lib/e2e'), async (importOriginal) => ({
...(await importOriginal()),
getE2EBuildCommand: () => mockedBuildCommand,
}));
Expand Down Expand Up @@ -625,6 +625,8 @@ describe('in CI', () => {

it('detects Netlify CI', async () => {
process.env = { REPOSITORY_URL: 'foo', DISABLE_LOGGING: 'true' };
process.stdout.isTTY = false; // vitest 2.0+ adds this property

const ctx = getContext(['--project-token=asdf1234']);
await runAll(ctx);
expect(ctx.exitCode).toBe(1);
Expand Down
4 changes: 2 additions & 2 deletions node-src/lib/checkForUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import semver from 'semver';
import { hasYarn } from 'yarn-or-npm';

import { InitialContext } from '..';
import { Context } from '..';
import outdatedPackage from '../ui/messages/warnings/outdatedPackage';
import spawn from './spawn';

const rejectIn = (ms: number) => new Promise<any>((_, reject) => setTimeout(reject, ms));
const withTimeout = <T>(promise: Promise<T>, ms: number): Promise<T> =>
Promise.race([promise, rejectIn(ms)]);

export default async function checkForUpdates(ctx: InitialContext) {
export default async function checkForUpdates(ctx: Context) {
if (ctx.options.skipUpdateCheck === true) {
ctx.log.info(`Skipping update check`);
return;
Expand Down
2 changes: 1 addition & 1 deletion node-src/tasks/initialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('setEnvironment', () => {
it('sets the environment info on context', async () => {
const ctx = { env, log } as any;
await setEnvironment(ctx);
expect(ctx.environment).toContain({
expect(ctx.environment).toMatchObject({
GERRIT_BRANCH: 'foo/bar',
TRAVIS_EVENT_TYPE: 'pull_request',
});
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"trim-stats": "./dist/bin.js trim-stats-file",
"storybook": "storybook dev -p 9009",
"test": "vitest run --coverage && vitest run -c vitest.no-threads.config.ts",
"typescript:check": "tsc --project ./tsconfig.json --noEmit",
"prepare": "husky install && npm run build",
"dev": "tsup --watch",
"lint-staged": "lint-staged"
Expand Down Expand Up @@ -137,7 +138,7 @@
"@types/webpack-env": "^1.18.5",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@vitest/coverage-v8": "^0.34.4",
"@vitest/coverage-v8": "^2.0.5",
"ansi-html": "0.0.8",
"any-observable": "^0.5.1",
"archiver": "^5.3.0",
Expand Down Expand Up @@ -205,7 +206,7 @@
"util-deprecate": "^1.0.2",
"uuid": "^8.3.2",
"vite": "^4.4.9",
"vitest": "^0.34.4",
"vitest": "^2.0.5",
"why-is-node-running": "^2.1.2",
"xxhash-wasm": "^1.0.2",
"yarn-or-npm": "^3.0.1",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"strict": false,
"noImplicitAny": false,
"resolveJsonModule": true,
"types": ["webpack-env"]
"types": ["webpack-env"],
"lib": ["es5", "es6", "dom"]
}
}
6 changes: 5 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/* eslint-disable import/no-unresolved */
import { configDefaults, defineConfig } from 'vitest/config';
import { configDefaults, coverageConfigDefaults, defineConfig } from 'vitest/config';

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, '**/getParentCommits.test.ts'],
coverage: {
provider: 'v8',
exclude: ['vitest.no-threads.config.ts', ...coverageConfigDefaults.exclude],
},
},
});
6 changes: 5 additions & 1 deletion vitest.no-threads.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
include: ['**/getParentCommits.test.ts'],
threads: false,
poolOptions: {
threads: {
singleThread: true,
},
},
},
});
Loading

0 comments on commit 253c46c

Please sign in to comment.