Skip to content

Commit

Permalink
fix: fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyingchun committed Jul 27, 2024
1 parent db7fe90 commit 697b6fe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-rice-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperse/install-local": patch
---

fix test cases
7 changes: 3 additions & 4 deletions tests/core/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ describe('cli', () => {
dependencies: string[];
save: boolean;
targetSiblings: boolean;
validate: Mock<any, Promise<void>>;
validate: Mock<() => Promise<void>>;
};

let currentDirectoryInstallStub: MockInstance<
[optionsModule.Options],
Promise<void>
(option: optionsModule.Options) => Promise<void>
>;
let siblingInstallStub: MockInstance<[], Promise<void>>;
let siblingInstallStub: MockInstance<() => Promise<void>>;

beforeEach(() => {
optionsMock = {
Expand Down
18 changes: 9 additions & 9 deletions tests/core/currentDirectoryInstall.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import type { WriteStream } from 'tty';
import { Mock } from 'vitest';
import { MockInstance } from 'vitest';
import { currentDirectoryInstall } from '../../src/currentDirectoryInstall.js';
import * as helpers from '../../src/helpers.js';
import { InstallTarget, Options, PackageJson } from '../../src/index.js';
import { InstallTarget, PackageJson, saveIfNeeded } from '../../src/index.js';
import * as localInstallerModule from '../../src/LocalInstaller.js';
import * as progressModule from '../../src/progress.js';
import * as saveModule from '../../src/save.js';
import { options, packageJson } from '../helpers/producers.js';

describe('currentDirectoryInstall', () => {
let localInstallerStub: { install: Mock<any, InstallTarget[]>; on: Mock };
let saveIfNeededStub: MockInstance<[InstallTarget[], Options], Promise<void>>;
let readPackageJsonStub: MockInstance<[string], Promise<PackageJson>>;
let progressStub: MockInstance<
[localInstallerModule.LocalInstaller, WriteStream?],
void
>;
let localInstallerStub: {
install: Mock<() => Promise<InstallTarget[]>>;
on: Mock;
};

let saveIfNeededStub: MockInstance<typeof saveIfNeeded>;
let readPackageJsonStub: MockInstance<(from: string) => Promise<PackageJson>>;
let progressStub: MockInstance<typeof progressModule.progress>;
beforeEach(() => {
localInstallerStub = { install: vi.fn(), on: vi.fn() };
// LocalInstaller is a class, so we need to mock the constructor, use `MockReturnValue` to mock the return value
Expand Down
2 changes: 1 addition & 1 deletion tests/core/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MockInstance } from 'vitest';
import { readPackageJson } from '../../src/helpers.js';

describe('Helpers', () => {
let readFileStub: MockInstance<any, Promise<string | Buffer>>;
let readFileStub: MockInstance<typeof fs.readFile>;

beforeEach(() => {
readFileStub = vi.spyOn(fs, 'readFile');
Expand Down

0 comments on commit 697b6fe

Please sign in to comment.