Skip to content

Commit

Permalink
fix: windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
didinele committed Aug 20, 2024
1 parent aef8558 commit 2e43e1c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
42 changes: 21 additions & 21 deletions packages/npm/readdir/src/__tests__/RecursiveReaddirStream.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { join as joinPath } from 'node:path';
import { beforeAll, expect, test, vi } from 'vitest';
import path from 'node:path';
import { expect, test, vi } from 'vitest';
import { readdirRecurse, readdirRecurseAsync, ReadMode } from '../index.js';

function platform(paths: string[]): string[] {
return paths.map((name) => name.replaceAll(path.posix.sep, path.sep));
}

/**
* Let's create a mock file system structure
* test has standard read tests
Expand Down Expand Up @@ -32,7 +37,7 @@ vi.mock('node:fs/promises', async (importOriginal) => {

return {
...original,
readdir: vi.fn<[string], Promise<string[]>>().mockImplementation(async (path) => {
readdir: vi.fn().mockImplementation(async (path) => {
switch (path) {
case joinPath('test'):
return ['dir1', 'dir2'];
Expand All @@ -50,7 +55,7 @@ vi.mock('node:fs/promises', async (importOriginal) => {
throw new Error(`bad path: ${path}`);
}
}),
stat: vi.fn<[string], Promise<{ isDirectory(): boolean }>>().mockImplementation(async (path) => {
stat: vi.fn().mockImplementation(async (path) => {
/* eslint-disable sonarjs/no-duplicated-branches */
switch (path) {
case joinPath('test'):
Expand Down Expand Up @@ -107,16 +112,13 @@ test('async iterator stream consumption', async () => {
files.push(file);
}

expect(files).toStrictEqual(['test/dir1', 'test/dir2', 'test/dir1/file1.sh', 'test/dir1/file2.js']);
expect(files).toStrictEqual(platform(['test/dir1', 'test/dir2', 'test/dir1/file1.sh', 'test/dir1/file2.js']));
});

test('promise based consumption', async () => {
expect(await readdirRecurseAsync(joinPath('test'), { readMode: ReadMode.both })).toStrictEqual([
'test/dir1',
'test/dir2',
'test/dir1/file1.sh',
'test/dir1/file2.js',
]);
expect(await readdirRecurseAsync(joinPath('test'), { readMode: ReadMode.both })).toStrictEqual(
platform(['test/dir1', 'test/dir2', 'test/dir1/file1.sh', 'test/dir1/file2.js']),
);

const catchCb = vi.fn();

Expand All @@ -126,25 +128,23 @@ test('promise based consumption', async () => {
});

test('read modes', async () => {
expect(await readdirRecurseAsync(joinPath('test'), { readMode: ReadMode.file })).toStrictEqual([
'test/dir1/file1.sh',
'test/dir1/file2.js',
]);

expect(await readdirRecurseAsync(joinPath('test'), { readMode: ReadMode.dir })).toStrictEqual([
'test/dir1',
'test/dir2',
]);
expect(await readdirRecurseAsync(joinPath('test'), { readMode: ReadMode.file })).toStrictEqual(
platform(['test/dir1/file1.sh', 'test/dir1/file2.js']),
);

expect(await readdirRecurseAsync(joinPath('test'), { readMode: ReadMode.dir })).toStrictEqual(
platform(['test/dir1', 'test/dir2']),
);
});

test('file extension filter', async () => {
expect(
await readdirRecurseAsync(joinPath('test'), { readMode: ReadMode.both, fileExtensions: ['sh'] }),
).toStrictEqual(['test/dir1', 'test/dir2', 'test/dir1/file1.sh']);
).toStrictEqual(platform(['test/dir1', 'test/dir2', 'test/dir1/file1.sh']));

expect(
await readdirRecurseAsync(joinPath('test'), { readMode: ReadMode.file, fileExtensions: ['sh'] }),
).toStrictEqual(['test/dir1/file1.sh']);
).toStrictEqual(platform(['test/dir1/file1.sh']));
});

test('warnings', async () => {
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"],
"inputs": ["tsconfig.json", "package.json", "src/**/*.ts", "tsup.config.ts", "prisma/schema.prisma"]
"inputs": ["tsconfig.json", "package.json", "src/**/*.ts", "tsup.config.ts", "schema.prisma"]
},
"lint": {
"dependsOn": ["^build"],
Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
typecheck: {
enabled: true,
include: ['**/__tests__/types.test.ts'],
tsconfig: 'tsconfig.json',
},
coverage: {
enabled: true,
Expand Down

0 comments on commit 2e43e1c

Please sign in to comment.