Skip to content

Commit

Permalink
refactor: move the existing search tests to webui
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Mar 31, 2024
1 parent a355a4f commit f28a1d3
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { describe, expect, it } from 'bun:test';

import { type StatsModule } from '../../data/types';
import { fuzzyFilterModules } from '../search';
import { globFilterModules } from '../search';

import { type StatsModule } from '~core/data/types';

const projectRoot = '/user/expo';
const modules = [
asModule({ path: '/user/expo/node_modules/lodash/lodash.js' }),
asModule({ path: '/user/expo/node_modules/expo/package.json' }),
Expand All @@ -14,39 +16,39 @@ function asModule(module: Pick<StatsModule, 'path'>) {
return module as StatsModule;
}

describe.skip('fuzzyGlobSearch', () => {
describe.skip('globFilterModules', () => {
describe('include', () => {
it('filters by exact file name', () => {
expect(fuzzyFilterModules(modules, { include: 'index.ts' })).toEqual([
expect(globFilterModules(modules, projectRoot, { include: 'index.ts' })).toEqual([
asModule({ path: '/user/expo/src/index.ts' }),
asModule({ path: '/user/expo/src/app/index.ts' }),
]);
});

it('filters by exact directory name', () => {
expect(fuzzyFilterModules(modules, { include: 'node_modules' })).toEqual([
expect(globFilterModules(modules, projectRoot, { include: 'node_modules' })).toEqual([
asModule({ path: '/user/expo/node_modules/lodash/lodash.js' }),
asModule({ path: '/user/expo/node_modules/expo/package.json' }),
]);
});

it('filters by multiple exact file or directory names', () => {
expect(fuzzyFilterModules(modules, { include: 'index.ts, lodash' })).toEqual([
expect(globFilterModules(modules, projectRoot, { include: 'index.ts, lodash' })).toEqual([
asModule({ path: '/user/expo/src/index.ts' }),
asModule({ path: '/user/expo/src/app/index.ts' }),
asModule({ path: '/user/expo/node_modules/lodash/lodash.js' }),
]);
});

it('filters using star pattern on directory', () => {
expect(fuzzyFilterModules(modules, { include: 'src/*' })).toEqual([
expect(globFilterModules(modules, projectRoot, { include: 'src/*' })).toEqual([
asModule({ path: '/user/expo/src/index.ts' }),
asModule({ path: '/user/expo/src/app/index.ts' }),
]);
});

it('filters using star pattern on nested directory', () => {
expect(fuzzyFilterModules(modules, { include: 'expo/src/**' })).toEqual([
expect(globFilterModules(modules, projectRoot, { include: 'expo/src/**' })).toEqual([
asModule({ path: '/user/expo/src/index.ts' }),
asModule({ path: '/user/expo/src/app/index.ts' }),
]);
Expand All @@ -55,34 +57,34 @@ describe.skip('fuzzyGlobSearch', () => {

describe('exclude', () => {
it('filters by exact file name', () => {
expect(fuzzyFilterModules(modules, { exclude: 'index.ts' })).toEqual([
expect(globFilterModules(modules, { exclude: 'index.ts' })).toEqual([
asModule({ path: '/user/expo/node_modules/lodash/lodash.js' }),
asModule({ path: '/user/expo/node_modules/expo/package.json' }),
]);
});

it('filters by exact directory name', () => {
expect(fuzzyFilterModules(modules, { exclude: 'node_modules' })).toEqual([
expect(globFilterModules(modules, { exclude: 'node_modules' })).toEqual([
asModule({ path: '/user/expo/src/index.ts' }),
asModule({ path: '/user/expo/src/app/index.ts' }),
]);
});

it('filters by multiple exact file or directory names', () => {
expect(fuzzyFilterModules(modules, { exclude: 'index.ts, lodash' })).toEqual([
expect(globFilterModules(modules, { exclude: 'index.ts, lodash' })).toEqual([
asModule({ path: '/user/expo/node_modules/expo/package.json' }),
]);
});

it('filters using star pattern on directory', () => {
expect(fuzzyFilterModules(modules, { exclude: 'src/*' })).toEqual([
expect(globFilterModules(modules, { exclude: 'src/*' })).toEqual([
asModule({ path: '/user/expo/node_modules/lodash/lodash.js' }),
asModule({ path: '/user/expo/node_modules/expo/package.json' }),
]);
});

it('filters using star pattern on nested directory', () => {
expect(fuzzyFilterModules(modules, { exclude: 'expo/src/**' })).toEqual([
expect(globFilterModules(modules, { exclude: 'expo/src/**' })).toEqual([
asModule({ path: '/user/expo/node_modules/lodash/lodash.js' }),
asModule({ path: '/user/expo/node_modules/expo/package.json' }),
]);
Expand Down

0 comments on commit f28a1d3

Please sign in to comment.