Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update vitest to 2.0 #5900

Merged
merged 4 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 1 addition & 4 deletions integration-tests/src/repositoryHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ const defaultTimeout = 60_000;

vi.mock('./config.js');

const mockAddRepository = configAddRepository as Mock<
Parameters<typeof configAddRepository>,
ReturnType<typeof configAddRepository>
>;
const mockAddRepository = configAddRepository as Mock<typeof configAddRepository>;

describe('Validate repository helper', () => {
interface TestCase {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"@rollup/plugin-typescript": "^11.1.6",
"@tsconfig/node18": "^18.2.4",
"@types/node": "^18.19.39",
"@vitest/coverage-istanbul": "^1.6.0",
"@vitest/coverage-istanbul": "^2.0.2",
"conventional-changelog-conventionalcommits": "^8.0.0",
"eslint": "^9.6.0",
"eslint-import-resolver-typescript": "^3.6.1",
Expand All @@ -129,6 +129,6 @@
"typescript": "^5.5.3",
"typescript-eslint": "^7.16.0",
"vite": "^5.3.3",
"vitest": "^1.6.0"
"vitest": "^2.0.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { defaultDeserializers } from './serializers/index.js';
import { fixtures } from './test-helpers/fixtures.js';
import { json } from './test-helpers/util.js';

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('CSpellConfigFileReaderWriter', () => {
test.each`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { defaultIO } from '../defaultIO.js';
import { fixtures } from '../test-helpers/fixtures.js';
import { loaderJavaScript } from './loaderJavaScript.js';

const oc = expect.objectContaining;
const ac = expect.arrayContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);
const ac = <T>(a: Array<T>) => expect.arrayContaining(a);

describe('loaderJavaScript', () => {
afterEach(() => {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { defaultNextDeserializer, defaultNextSerializer } from '../defaultNext.j
import { json } from '../test-helpers/util.js';
import { serializerCSpellJson } from './cspellJson.js';

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

const next = defaultNextDeserializer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CSpellConfigFileYaml } from '../CSpellConfigFile/CSpellConfigFileYaml.j
import { defaultNextDeserializer } from '../defaultNext.js';
import { serializerCSpellYaml } from './cspellYaml.js';

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);
const next = defaultNextDeserializer;

describe('cspellYaml', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { defaultNextDeserializer, defaultNextSerializer } from '../defaultNext.j
import { json } from '../test-helpers/util.js';
import { serializerPackageJson } from './packageJson.js';

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);
const next = defaultNextDeserializer;

describe('packageJson', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createSpellingDictionary } from './createSpellingDictionary.js';
import { createCollection } from './SpellingDictionaryCollection.js';
import { createSuggestDictionary } from './SuggestDictionary.js';

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('CachingDictionary', () => {
const words = ['apple', 'banana', 'orange', 'grape', 'mango', '!pear'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, test } from 'vitest';

import { createFlagWordsDictionary } from './FlagWordsDictionary.js';

// const oc = expect.objectContaining;
// const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('ForbiddenWordsDictionary', () => {
const dictWords = [' english', '!English', 'grumpy', 'Avocado', 'avocadoS', '!avocado'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, test } from 'vitest';

import { createIgnoreWordsDictionary } from './IgnoreWordsDictionary.js';

// const oc = expect.objectContaining;
// const oc = <T>(obj: T) => expect.objectContaining(obj);

// cspell:ignore êphone îphone geschäft

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, test } from 'vitest';

import { createSuggestDictionary } from './SuggestDictionary.js';

// const oc = expect.objectContaining;
// const oc = <T>(obj: T) => expect.objectContaining(obj);
const isPreferred = true;

describe('SuggestDictionary 1', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, test } from 'vitest';

import { createTyposDictionary } from './TyposDictionary.js';

// const oc = expect.objectContaining;
// const oc = <T>(obj: T) => expect.objectContaining(obj);
const isPreferred = true;

describe('TyposDictionary 1', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/cspell-gitignore/src/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as path from 'node:path';

import type { SpyInstance } from 'vitest';
import type { MockInstance } from 'vitest';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';

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

describe('app', () => {
let log: SpyInstance<Parameters<typeof console.log>>;
let error: SpyInstance<Parameters<typeof console.error>>;
let log: MockInstance<typeof console.log>;
let error: MockInstance<typeof console.error>;

beforeEach(() => {
log = vi.spyOn(console, 'log').mockImplementation(() => undefined);
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-glob/src/GlobMatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const pathNames = new Map([
[pathPosix, 'Posix'],
]);

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

function r(...parts: string[]) {
return path.resolve(...parts);
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-grammar/src/parser/tokenizeLine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { normalizeGrammar } from './grammarNormalizer.js';
import { tokenizeText } from './tokenizeLine.js';
import type { TokenizedLine } from './types.js';

// const oc = expect.objectContaining;
// const oc = <T>(obj: T) => expect.objectContaining(obj);

const grammar = normalizeGrammar(Simple.grammar);
const grammarTypeScript = normalizeGrammar(TypeScript.grammar);
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-io/src/CSpellIONode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { CSpellIONode } from './CSpellIONode.js';
import { toFileURL } from './node/file/url.js';
import { makePathToFile, pathToSample as ps, pathToTemp } from './test/test.helper.js';

const sc = expect.stringContaining;
const oc = expect.objectContaining;
const sc = (m: string) => expect.stringContaining(m);
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('CSpellIONode', () => {
test('constructor', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-io/src/VirtualFS/redirectProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { VFSErrorUnsupportedRequest } from './WrappedProviderFs.js';

const samplesURL = pathToSampleURL();

const sc = expect.stringContaining;
const oc = expect.objectContaining;
const sc = (m: string) => expect.stringContaining(m);
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('Validate RedirectProvider', () => {
test('createRedirectProvider', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-io/src/VirtualFs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { FSCapabilityFlags } from './VFileSystem.js';
import type { VFileSystemProvider, VirtualFS, VProviderFileSystem } from './VirtualFS.js';
import { VFSErrorUnsupportedRequest } from './VirtualFS/WrappedProviderFs.js';

const sc = expect.stringContaining;
const oc = expect.objectContaining;
const sc = (m: string) => expect.stringContaining(m);
const oc = <T>(obj: T) => expect.objectContaining(obj);

let mockConsoleLog = vi.spyOn(console, 'log');

Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-io/src/node/dataUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, expect, test } from 'vitest';
import { pathToSample } from '../test/test.helper.js';
import { decodeDataUrl, encodeDataUrl, encodeDataUrlFromFile, guessMimeType, toDataUrl } from './dataUrl.js';

const sc = expect.stringContaining;
const sc = (m: string) => expect.stringContaining(m);

describe('dataUrl', () => {
test.each`
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-io/src/node/file/FetchError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, test } from 'vitest';
import { FetchUrlError, toError, toFetchUrlError } from './FetchError.js';
import { toURL } from './url.js';

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('FetchError', () => {
test.each`
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-io/src/node/file/stat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { describe, expect, test } from 'vitest';

import { getStat, getStatSync } from './stat.js';

const oc = expect.objectContaining;
const sc = expect.stringContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);
const sc = (m: string) => expect.stringContaining(m);

const timeout = 20_000;

Expand Down
6 changes: 3 additions & 3 deletions packages/cspell-io/src/node/file/url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { describe, expect, test } from 'vitest';
import { basename, isUrlLike, toFileURL, toURL, urlBasename, urlDirname } from './url.js';

const root = path.join(__dirname, '../..');
const oc = expect.objectContaining;
// const sc = expect.stringContaining;
const sm = expect.stringMatching;
const oc = <T>(obj: T) => expect.objectContaining(obj);
// const sc = (m: string) => expect.stringContaining(m);
const sm = (m: string | RegExp) => expect.stringMatching(m);

describe('util', () => {
test.each`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { _defaultSettings, getDefaultBundledSettingsAsync } from './DefaultSetti

const samplesDir = pathPackageSamples;
const pathSrc = path.join(pathPackageRoot, 'src');
const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('Validate CSpellSettingsServer', () => {
test('tests mergeSettings with conflicting "name"', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const testFixtures = pathRepoTestFixtures;

const urlIssues = new URL('issues/', pathRepoTestFixturesURL);

const oc = expect.objectContaining;
const sm = expect.stringMatching;
const oc = <T>(obj: T) => expect.objectContaining(obj);
const sm = (m: string | RegExp) => expect.stringMatching(m);

vi.mock('../../../util/logger');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as DictSettings from './DictionarySettings.js';
const __filename = fileURLToPath(import.meta.url);

const defaultSettings = await getDefaultBundledSettingsAsync();
const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('Validate DictionarySettings', () => {
test('expects default to not be empty', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ vi.mock('node:fs/promises', async (_importOriginal) => ({
},
}));

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('Validate GlobalSettings', () => {
beforeEach(() => {});
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-lib/src/lib/Settings/InDocSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import * as InDoc from './InDocSettings.js';

const dictName = InDoc.internal.staticInDocumentDictionaryName;

const oc = expect.objectContaining;
const ac = expect.arrayContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);
const ac = <T>(a: Array<T>) => expect.arrayContaining(a);
const nac = expect.not.arrayContaining;

// cSpell:ignore faullts straange tooo
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-lib/src/lib/Settings/cfgStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ vi.mock('node:fs/promises', async (_importOriginal) => ({
},
}));

const sc = expect.stringContaining;
const oc = expect.objectContaining;
const sc = (m: string) => expect.stringContaining(m);
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('GlobalConfigStore', () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/lib/Settings/mergeCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import { dispatchClearCache } from '../events/events.js';
import { CalcLeftRightResultWeakCache } from './mergeCache.js';

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('CalcLeftRightResultWeakCache', () => {
let cache: CalcLeftRightResultWeakCache<object, object, number>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ErrorResults = Record<string, unknown> | Error;

const di = mapDictDefToInternal;

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('Validate DictionaryLoader', () => {
const errorENOENT = { code: 'ENOENT' };
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-lib/src/lib/spellCheckFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const hasDriveLetter = /^[A-Z]:\\/i;

const { toEqualCaseInsensitive: expectToEqualCaseInsensitive } = extendExpect(expect);

const oc = expect.objectContaining;
const sc = expect.stringContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);
const sc = (m: string) => expect.stringContaining(m);

describe('Validate Spell Checking Files', () => {
interface TestSpellCheckFile {
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-lib/src/lib/suggestions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { SuggestionOptions } from './suggestions.js';
import { SuggestionError, suggestionsForWord, suggestionsForWords } from './suggestions.js';
import { asyncIterableToArray } from './util/util.js';

const oc = expect.objectContaining;
const ac = expect.arrayContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);
const ac = <T>(a: Array<T>) => expect.arrayContaining(a);

const timeout = 20_000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const __filename = fileURLToPath(import.meta.url);

const samples = pathPackageSamples;
const cfgPath = path.join(samples, '.cspell.json');
const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('determineTextDocumentSettings', () => {
test.each`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const __filename = fileURLToPath(import.meta.url);
const docCache = new AutoCache(_loadDoc, 100);
const fixturesDir = pathPackageFixtures;

const oc = expect.objectContaining;
const ac = expect.arrayContaining;
const sc = expect.stringContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);
const ac = <T>(a: Array<T>) => expect.arrayContaining(a);
const sc = (m: string) => expect.stringContaining(m);

const { sanitizeSuggestion } = __testing__;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, expect, test } from 'vitest';

import { textValidatorFactory } from './lineValidatorFactory.js';

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('lineValidatorFactory', () => {
test.each`
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-lib/src/lib/textValidation/traceWord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const fixturesURL = new URL('traceWords/', pathPackageFixturesURL);
const urlReadme = new URL('README.md', fixturesURL);
const expectedConfigURL = new URL('cspell.config.yaml', fixturesURL);

const ac = expect.arrayContaining;
const oc = expect.objectContaining;
const ac = <T>(a: Array<T>) => expect.arrayContaining(a);
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('traceWord', async () => {
const doc: TextDocumentRef = { uri: toUri(import.meta.url), languageId: 'typescript' };
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-lib/src/lib/textValidation/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import * as Validator from './validator.js';

// cSpell:ignore brouwn jumpped lazzy wrongg mispelled ctrip nmove mischecked

const ac = expect.arrayContaining;
const ac = <T>(a: Array<T>) => expect.arrayContaining(a);
const notAc = expect.not.arrayContaining;

const oc = expect.objectContaining;
const oc = <T>(obj: T) => expect.objectContaining(obj);

describe('Validator', () => {
test('validates the validator', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/lib/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { traceWords } from './trace.js';

const timeout = 20_000;

const ac = expect.arrayContaining;
const ac = <T>(a: Array<T>) => expect.arrayContaining(a);

const testOptions: TestOptions = { timeout };

Expand Down
Loading