Skip to content
Draft
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .changeset/fine-chairs-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'skuba': minor
---

api, lint, migrate, test: Use Vitest globals by default

skuba's dependency hoisting setup is incompatible with TypeScript's import suggestion system, so new test files won't receive Intellisense suggestions for `vitest` imports until it is imported manually in the test file.

To address this limitation we now use Vitest's globals by default

This patch will automatically remove Vitest imports from all test files.

If your `vitest.config.ts` files are using the `Vitest.mergePreset` function, you should not need to update anything.

However, if you have custom `vitest.config.ts` files, or are using `projects` without the `extends: true` option, you may need to update your config to use Vitest's globals.

```diff
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
+ globals: true,
},
});
```
4 changes: 2 additions & 2 deletions .changeset/renovate-237bb40.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ deps: typescript ~6.0.0

This major release contains breaking changes. See the [TypeScript 6.0.0](https://devblogs.microsoft.com/typescript/announcing-typescript-6-0/) announcement for more information.

If your tsconfig currently extends `skuba/config/tsconfig.json`, you may not need to update anything. However, if you have a custom configuration, you may need to manually add `node` to the `types` array.
If your tsconfig currently extends `skuba/config/tsconfig.json`, you may not need to update anything. However, if you have a custom configuration or run into lint errors related to missing Vitest globals, you may need to manually add `node` and `vitest/globals` to the `types` array in your tsconfig:
Comment thread
samchungy marked this conversation as resolved.
Outdated

```diff
{
"compilerOptions": {
+ "types": ["node"]
+ "types": ["node", "vitest/globals"]
}
}
```
2 changes: 1 addition & 1 deletion config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"noUnusedLocals": false,
"noUnusedParameters": false,
"resolveJsonModule": true,
"types": ["node"]
"types": ["node", "vitest/globals"]
},
"extends": "tsconfig-seek"
}
2 changes: 0 additions & 2 deletions packages/api/src/buildkite/annotate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import * as execModule from '../../../../src/utils/exec.js';
import { log } from '../../../../src/utils/logging.js';

Expand Down
2 changes: 0 additions & 2 deletions packages/api/src/buildkite/md.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { md } from './md.js';

describe('terminal', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/api/src/cdk/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { normaliseTemplate } from './index.js';

describe('normaliseTemplate', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/commit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import git from 'isomorphic-git';
import { afterEach, describe, expect, it, vi } from 'vitest';

import { commit } from './commit.js';

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/commitAllChanges.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from 'path';

import git from 'isomorphic-git';
import memfs, { fs, vol } from 'memfs';
import { beforeEach, expect, it, vi } from 'vitest';

import newGit from '../../../../integration/git/new.json' with { type: 'json' };

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/currentBranch.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import git from 'isomorphic-git';
import memfs, { vol } from 'memfs';
import { beforeEach, expect, it, vi } from 'vitest';

import { currentBranch } from './currentBranch.js';

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/currentBranch.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import git from 'isomorphic-git';
import { afterEach, describe, expect, it, vi } from 'vitest';

import { currentBranch } from './currentBranch.js';

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/findRoot.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import memfs, { vol } from 'memfs';
import { beforeEach, expect, it, vi } from 'vitest';

import { findRoot } from './findRoot.js';

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/getChangedFiles.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import git from 'isomorphic-git';
import memfs, { fs, vol } from 'memfs';
import { beforeEach, expect, it, vi } from 'vitest';

import newGit from '../../../../integration/git/new.json' with { type: 'json' };

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/log.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import git from 'isomorphic-git';
import { afterEach, describe, expect, it, vi } from 'vitest';

import { getHeadCommitId, getHeadCommitMessage } from './log.js';

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/pull.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import git from 'isomorphic-git';
import { afterEach, describe, expect, it, vi } from 'vitest';

import { fastForwardBranch } from './pull.js';

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/push.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import git from 'isomorphic-git';
import { afterEach, describe, expect, it, vi } from 'vitest';

import { push } from './push.js';

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/remote.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import git from 'isomorphic-git';
import memfs, { vol } from 'memfs';
import { beforeEach, expect, it, vi } from 'vitest';

import { getOwnerAndRepo } from './remote.js';

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/remote.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import git from 'isomorphic-git';
import { afterEach, describe, expect, it, vi } from 'vitest';

import { getOwnerAndRepo } from './remote.js';

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/git/reset.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import git from 'isomorphic-git';
import memfs, { fs, vol } from 'memfs';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import newGit from '../../../../integration/git/new.json' with { type: 'json' };

Expand Down
1 change: 0 additions & 1 deletion packages/api/src/github/checkRun.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Endpoints } from '@octokit/types';
import git, { type ReadCommitResult } from 'isomorphic-git';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { createCheckRun } from './checkRun.js';
import { createRestClient } from './octokit.js';
Expand Down
2 changes: 0 additions & 2 deletions packages/api/src/github/environment.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import {
apiTokenFromEnvironment,
buildNameFromEnvironment,
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/github/issueComment.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import git from 'isomorphic-git';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { putIssueComment } from './issueComment.js';
import { createRestClient } from './octokit.js';
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/github/pullRequest.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import git from 'isomorphic-git';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { createRestClient } from './octokit.js';
import { getPullRequestNumber } from './pullRequest.js';
Expand Down
10 changes: 0 additions & 10 deletions packages/api/src/github/push.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import type { FileChanges } from '@octokit/graphql-schema';
import fs from 'fs-extra';
import git, { type ReadCommitResult } from 'isomorphic-git';
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
vi,
} from 'vitest';

import { apiTokenFromEnvironment } from './environment.js';
import { graphql } from './octokit.js';
Expand Down
1 change: 1 addition & 0 deletions packages/api/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
coverage: {
thresholds: {
branches: 84,
Expand Down
1 change: 0 additions & 1 deletion packages/detect-invalid-spies/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import os from 'node:os';
import path from 'node:path';

import fs from 'fs-extra';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';

import { detectSameFileSpyUsage } from './index.js';

Expand Down
1 change: 1 addition & 0 deletions packages/detect-invalid-spies/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
exclude: ['**/node_modules'],
},
});
2 changes: 0 additions & 2 deletions packages/skuba-dive/src/assert/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import {
notNullish,
nullish,
Expand Down
2 changes: 0 additions & 2 deletions packages/skuba-dive/src/env/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { beforeEach, describe, expect, it } from 'vitest';

import { create } from './create.js';

describe('create', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/skuba-dive/src/env/parsers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import * as parsers from './parsers.js';

describe('nonNegativeInteger', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/skuba-dive/src/env/presets.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, test } from 'vitest';

import * as presets from './presets.js';

describe('presets', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/skuba-dive/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import * as skubaDive from './index.js';

describe('skuba-dive', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/vitest-koa-mocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ Create a standalone mock cookies implementation for Koa-style code.

```typescript
import { createMockCookies } from '@skuba-lib/vitest-koa-mocks';
import { expect, it } from 'vitest';

it('tracks request and response cookies', () => {
const cookies = createMockCookies({ session: 'abc' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Context } from 'koa';
import { describe, expect, it, vi } from 'vitest';

import { createMockContext } from './createMockContext.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { createMockCookies } from './createMockCookies.js';

describe('create-mock-cookies', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/vitest-koa-mocks/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
include: ['src/**/*.test.ts'],
coverage: {
include: ['src'],
Expand Down
1 change: 1 addition & 0 deletions src/api/vitest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type ViteUserConfig, defaultExclude } from 'vitest/config';
import { mergeRaw } from '../../cli/configure/processing/record.js';

export const defaults = {
globals: true,
coverage: {
include: ['**/*.ts', '**/*.tsx'],
exclude: [
Expand Down
2 changes: 0 additions & 2 deletions src/cli/adapter/prettier.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable no-console */
import path from 'path';

import { afterAll, beforeAll, describe, expect, it, test } from 'vitest';

import { log } from '../../utils/logging.js';

import { inferParser, runPrettier } from './prettier.js';
Expand Down
2 changes: 0 additions & 2 deletions src/cli/build/args.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import path from 'path';

import { describe, expect, it } from 'vitest';

import { parseTscArgs } from './args.js';

describe('parseTscArgs', () => {
Expand Down
1 change: 0 additions & 1 deletion src/cli/build/assets.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import memfs, { vol } from 'memfs';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { copyAssets } from './assets.js';

Expand Down
2 changes: 0 additions & 2 deletions src/cli/build/tsc.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import path from 'path';

import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';

import { getCustomConditions } from './tsc.js';

describe('getCustomConditions', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/analysis/package.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, test } from 'vitest';

import { diffDependencies } from './package.js';

describe('diffDependencies', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/analysis/project.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it, vi } from 'vitest';

import * as dir from '../../../utils/dir.js';
import { getSkubaVersion } from '../../../utils/version.js';
import { defaultOpts } from '../testing/module.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { seekDatadogCustomMetrics } from './seekDatadogCustomMetrics.js';

describe('seekDatadogCustomMetrics', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/dependencies/seekKoala.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { seekKoala } from './seekKoala.js';

describe('seekKoala', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/dependencies/skuba.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { skuba } from './skuba.js';

describe('skuba', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/dependencies/skubaDeps.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { skubaDeps } from './skubaDeps.js';

describe('skubaDeps', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/dependencies/skubaDive.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { skubaDive } from './skubaDive.js';

describe('skubaDive', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/modules/eslint.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { defaultOpts, executeModule } from '../testing/module.js';

import { eslintModule } from './eslint.js';
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/modules/ignore.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { defaultOpts, executeModule } from '../testing/module.js';

import { ignoreModule } from './ignore.js';
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/modules/nodemon.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { defaultOpts, executeModule } from '../testing/module.js';

import { nodemonModule } from './nodemon.js';
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/modules/package.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { parsePackage } from '../processing/package.js';
import {
assertDefined,
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/modules/prettier.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { defaultOpts, executeModule } from '../testing/module.js';

import { prettierModule } from './prettier.js';
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/modules/renovate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import {
defaultOpts,
defaultPackageOpts,
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/modules/serverless.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { defaultOpts, executeModule } from '../testing/module.js';

import { serverlessModule } from './serverless.js';
Expand Down
2 changes: 0 additions & 2 deletions src/cli/configure/modules/tslint.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { describe, expect, it } from 'vitest';

import { defaultOpts, executeModule } from '../testing/module.js';

import { tslintModule } from './tslint.js';
Expand Down
Loading