Skip to content

Commit

Permalink
enable code coverage (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Superchupu <[email protected]>
  • Loading branch information
Jayllyz and SuperchupuDev authored Aug 6, 2024
1 parent 829cca3 commit 1b51f7b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: pnpm install --frozen-lockfile

- name: Run tests
run: node --run test
run: node --run test:cov

typescript:
name: TypeScript
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "biome lint",
"lint:fix": "biome lint --fix --unsafe",
"test": "tsx --test",
"test:cov": "tsx --test --experimental-test-coverage",
"typecheck": "tsc --noEmit"
},
"main": "dist/index.js",
Expand Down
59 changes: 57 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import path from 'node:path';
import { test } from 'node:test';
import { glob, globSync } from '../src';
import { glob, globSync } from '../src/index.js';

const cwd = path.join(__dirname, '../fixtures');

Expand All @@ -11,7 +11,7 @@ test('directory expansion', async () => {
});

test('empty array matches nothing', async () => {
const files = await glob({ patterns: [], cwd });
const files = await glob({ patterns: [] });
assert.deepEqual(files.sort(), []);
});

Expand All @@ -28,6 +28,9 @@ test('classic patterns as first argument', async () => {
test("cant have both classic patterns and options' patterns", async () => {
// @ts-expect-error
assert.rejects(glob(['a/*.ts'], { patterns: ['whoops!'], cwd }));

// @ts-expect-error
assert.throws(() => globSync(['a/*.ts'], { patterns: ['whoops!'], cwd }));
});

test('negative patterns', async () => {
Expand Down Expand Up @@ -60,6 +63,11 @@ test('matching only a directory works', async () => {
assert.deepEqual(files.sort(), ['a/']);
});

test('expandDirectories true', async () => {
const files = await glob({ patterns: ['a'], expandDirectories: true, cwd });
assert.deepEqual(files.sort(), ['a/a.ts', 'a/b.ts']);
});

test('handle absolute patterns to some extent', async () => {
const files = await glob({ patterns: [`${cwd.replaceAll('\\', '/')}/a/a.ts`], cwd });
assert.deepEqual(files.sort(), ['a/a.ts']);
Expand All @@ -81,6 +89,9 @@ test('deep', async () => {

const files2 = await glob({ patterns: ['.deep/a/a/*.ts'], deep: 2, cwd });
assert.deepEqual(files2.sort(), []);

const files3 = await glob({ patterns: ['.deep/a/a/*.ts'], deep: 1, cwd });
assert.deepEqual(files3.sort(), []);
});

test('absolute + dot', async () => {
Expand Down Expand Up @@ -108,7 +119,51 @@ test('**/* works', async () => {
assert.deepEqual(files.sort(), ['a/a.ts', 'a/b.ts', 'b/a.ts', 'b/b.ts']);
});

test('matching files with specific naming pattern', async () => {
const files = await glob({ patterns: ['**/[a-c].ts'], cwd });
assert.deepEqual(files.sort(), ['a/a.ts', 'a/b.ts', 'b/a.ts', 'b/b.ts']);
});

test('using extglob patterns', async () => {
const files = await glob({ patterns: ['a/*(a|b).ts'], cwd });
assert.deepEqual(files.sort(), ['a/a.ts', 'a/b.ts']);
});

test('pattern normalization', async () => {
const files1 = await glob({ patterns: ['a/'], cwd });
const files2 = await glob({ patterns: ['a'], cwd });
assert.deepEqual(files1, files2);
});

test('negative patterns in options', async () => {
const files = await glob({ patterns: ['**/*.ts', '!**/b.ts'], cwd });
assert.deepEqual(files.sort(), ['a/a.ts', 'b/a.ts']);

const files2 = await glob({ patterns: ['**/*.ts', '!**/a.ts'], cwd });
assert.deepEqual(files2.sort(), ['a/b.ts', 'b/b.ts']);
});

test('sync version', () => {
const files = globSync({ patterns: ['a/*.ts'], cwd });
assert.deepEqual(files.sort(), ['a/a.ts', 'a/b.ts']);
});

test('sync version with no patterns', () => {
const files = globSync({ cwd });
assert.deepEqual(files.sort(), ['a/a.ts', 'a/b.ts', 'b/a.ts', 'b/b.ts']);
});

test('sync version with no patterns and onlyDirectories', () => {
const files = globSync({ cwd, onlyDirectories: true });
assert.deepEqual(files.sort(), ['a/', 'b/']);
});

test('sync version with multiple patterns', () => {
const files = globSync({ patterns: ['a/*.ts', 'b/*.ts'], cwd });
assert.deepEqual(files.sort(), ['a/a.ts', 'a/b.ts', 'b/a.ts', 'b/b.ts']);
});

test('sync with empty array matches nothing', () => {
const files = globSync({ patterns: [] });
assert.deepEqual(files.sort(), []);
});

0 comments on commit 1b51f7b

Please sign in to comment.