Skip to content

Commit

Permalink
tests for loading config files from cjs and esm projects
Browse files Browse the repository at this point in the history
  • Loading branch information
antonk52 committed Feb 7, 2024
1 parent aa33d1a commit 009fd28
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/spec/cjs-project/cjs.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
cjs: true,
};
3 changes: 3 additions & 0 deletions src/spec/cjs-project/cjs.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
cjs: true,
};
3 changes: 3 additions & 0 deletions src/spec/cjs-project/cjs.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
esm: true,
};
12 changes: 12 additions & 0 deletions src/spec/cjs-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "cjs-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
3 changes: 3 additions & 0 deletions src/spec/esm-project/esm.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
cjs: true,
};
3 changes: 3 additions & 0 deletions src/spec/esm-project/esm.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
esm: true,
};
3 changes: 3 additions & 0 deletions src/spec/esm-project/esm.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
esm: true,
};
12 changes: 12 additions & 0 deletions src/spec/esm-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "esm-package",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
208 changes: 208 additions & 0 deletions src/spec/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,214 @@ describe('options', () => {
expect(ccResult).toEqual({config, filepath});
});

describe('esm-project', () => {
it('async search js', async () => {
const stopDir = __dirname;
const filepath = path.join(
stopDir,
'esm-project',
'esm.config.js',
);
const searchFrom = path.join(
stopDir,
'esm-project',
'a',
'b',
'c',
);

const options = {
searchPlaces: ['esm.config.js'],
stopDir,
};

const config = {esm: true};

const result = await lilconfig('test-app', options).search(
searchFrom,
);
const ccResult = await cosmiconfig(
'test-app',
options,
).search(searchFrom);

expect(result).toEqual({config, filepath});
expect(ccResult).toEqual({config, filepath});
});

it('async search mjs', async () => {
const stopDir = __dirname;
const filepath = path.join(
stopDir,
'esm-project',
'esm.config.mjs',
);
const searchFrom = path.join(
stopDir,
'esm-project',
'a',
'b',
'c',
);

const options = {
searchPlaces: ['esm.config.mjs'],
stopDir,
};

const config = {esm: true};

const result = await lilconfig('test-app', options).search(
searchFrom,
);
const ccResult = await cosmiconfig(
'test-app',
options,
).search(searchFrom);

expect(result).toEqual({config, filepath});
expect(ccResult).toEqual({config, filepath});
});

it('async search cjs', async () => {
const stopDir = __dirname;
const filepath = path.join(
stopDir,
'esm-project',
'esm.config.cjs',
);
const searchFrom = path.join(
stopDir,
'esm-project',
'a',
'b',
'c',
);

const options = {
searchPlaces: ['esm.config.cjs'],
stopDir,
};

const config = {cjs: true};

const result = await lilconfig('test-app', options).search(
searchFrom,
);
const ccResult = await cosmiconfig(
'test-app',
options,
).search(searchFrom);

expect(result).toEqual({config, filepath});
expect(ccResult).toEqual({config, filepath});
});
});

describe('cjs-project', () => {
it('async search js', async () => {
const stopDir = __dirname;
const filepath = path.join(
stopDir,
'cjs-project',
'cjs.config.js',
);
const searchFrom = path.join(
stopDir,
'cjs-project',
'a',
'b',
'c',
);

const options = {
searchPlaces: ['cjs.config.js'],
stopDir,
};

const config = {cjs: true};

const result = await lilconfig('test-app', options).search(
searchFrom,
);
const ccResult = await cosmiconfig(
'test-app',
options,
).search(searchFrom);

expect(result).toEqual({config, filepath});
expect(ccResult).toEqual({config, filepath});
});

it('async search mjs', async () => {
const stopDir = __dirname;
const filepath = path.join(
stopDir,
'cjs-project',
'cjs.config.mjs',
);
const searchFrom = path.join(
stopDir,
'cjs-project',
'a',
'b',
'c',
);

const options = {
searchPlaces: ['cjs.config.mjs'],
stopDir,
};

const config = {esm: true};

const result = await lilconfig('test-app', options).search(
searchFrom,
);
const ccResult = await cosmiconfig(
'test-app',
options,
).search(searchFrom);

expect(result).toEqual({config, filepath});
expect(ccResult).toEqual({config, filepath});
});

it('async search cjs', async () => {
const stopDir = __dirname;
const filepath = path.join(
stopDir,
'cjs-project',
'cjs.config.cjs',
);
const searchFrom = path.join(
stopDir,
'cjs-project',
'a',
'b',
'c',
);

const options = {
searchPlaces: ['cjs.config.cjs'],
stopDir,
};

const config = {cjs: true};

const result = await lilconfig('test-app', options).search(
searchFrom,
);
const ccResult = await cosmiconfig(
'test-app',
options,
).search(searchFrom);

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');
Expand Down

0 comments on commit 009fd28

Please sign in to comment.