Skip to content

Commit

Permalink
tests for no extension loader
Browse files Browse the repository at this point in the history
  • Loading branch information
antonk52 committed Nov 16, 2023
1 parent 5c6e3ac commit abe9528
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/spec/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ describe('options', () => {
describe('async loaders', () => {
const config = {data: 42};
const options = {
loaders: {'.js': async () => config},
loaders: {
'.js': async () => config,
noExt: (_: string, content: string) => content,
},
};

it('async load', async () => {
Expand Down Expand Up @@ -109,6 +112,54 @@ describe('options', () => {
expect(result).toEqual({config, filepath});
expect(ccResult).toEqual({config, filepath});
});

it('async noExt', async () => {
const searchPath = path.join(__dirname, 'search');
const filepath = path.join(searchPath, 'noExtension');
const opts = {
...options,
searchPlaces: ['noExtension'],
};

const result = await lilconfig('noExtension', opts).search(
searchPath,
);
const ccResult = await cosmiconfig('noExtension', opts).search(
searchPath,
);

const expected = {
filepath,
config: 'this file has no extension\n',
};

expect(result).toEqual(expected);
expect(ccResult).toEqual(expected);
});

it('sync noExt', () => {
const searchPath = path.join(__dirname, 'search');
const filepath = path.join(searchPath, 'noExtension');
const opts = {
...options,
searchPlaces: ['noExtension'],
};

const result = lilconfigSync('noExtension', opts).search(
searchPath,
);
const ccResult = cosmiconfigSync('noExtension', opts).search(
searchPath,
);

const expected = {
filepath,
config: 'this file has no extension\n',
};

expect(result).toEqual(expected);
expect(ccResult).toEqual(expected);
});
});
});

Expand Down
1 change: 1 addition & 0 deletions src/spec/search/noExtension
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this file has no extension

0 comments on commit abe9528

Please sign in to comment.