2021-09-30 10:13:13 +00:00
|
|
|
/*
|
|
|
|
* *** MIT LICENSE ***
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
* This code may be modified and distributed under the MIT license.
|
|
|
|
* See the LICENSE file for details.
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* @summary Tests on config generation
|
|
|
|
*
|
|
|
|
* @author Alvis HT Tang <alvis@hilbert.space>
|
|
|
|
* @license MIT
|
|
|
|
* @copyright Copyright (c) 2020 - All Rights Reserved.
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2023-05-05 11:20:29 +00:00
|
|
|
import { readdirSync } from 'node:fs';
|
|
|
|
import { resolve } from 'node:path';
|
2022-07-14 21:55:47 +00:00
|
|
|
import { loadDynamicMap, resolveContext } from 'presetter';
|
2021-09-30 10:13:13 +00:00
|
|
|
|
|
|
|
import getPresetAsset from '#index';
|
|
|
|
|
2023-05-05 11:20:29 +00:00
|
|
|
jest.mock('node:path', () => ({
|
2021-09-30 10:13:13 +00:00
|
|
|
__esModule: true,
|
2023-05-05 11:20:29 +00:00
|
|
|
...jest.requireActual('node:path'),
|
|
|
|
resolve: jest.fn(jest.requireActual('node:path').resolve),
|
2021-09-30 10:13:13 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('fn:getPresetAsset', () => {
|
|
|
|
it('use all templates', async () => {
|
2022-09-23 12:21:03 +00:00
|
|
|
const asset = getPresetAsset();
|
2022-07-14 21:55:47 +00:00
|
|
|
const context = await resolveContext({
|
|
|
|
graph: [{ name: 'preset', asset, nodes: [] }],
|
|
|
|
context: {
|
|
|
|
target: { name: 'preset', root: '/', package: {} },
|
|
|
|
custom: { preset: 'preset' },
|
|
|
|
},
|
2021-09-30 10:13:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// load all potential dynamic content
|
2022-07-14 21:55:47 +00:00
|
|
|
await loadDynamicMap(asset.supplementaryConfig, context);
|
|
|
|
await loadDynamicMap(asset.template, context);
|
2021-09-30 10:13:13 +00:00
|
|
|
|
|
|
|
const TEMPLATES = resolve(__dirname, '..', 'templates');
|
2022-09-23 12:21:03 +00:00
|
|
|
const allTemplates = readdirSync(TEMPLATES);
|
2021-09-30 10:13:13 +00:00
|
|
|
const CONFIGS = resolve(__dirname, '..', 'configs');
|
2022-09-23 12:21:03 +00:00
|
|
|
const supplementaryConfig = readdirSync(CONFIGS);
|
2021-09-30 10:13:13 +00:00
|
|
|
|
|
|
|
for (const path of allTemplates) {
|
|
|
|
expect(resolve).toBeCalledWith(TEMPLATES, path);
|
|
|
|
}
|
|
|
|
for (const path of supplementaryConfig) {
|
|
|
|
expect(resolve).toBeCalledWith(CONFIGS, path);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|