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.
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { readdirSync } from 'fs';
|
|
|
|
import { resolve } from '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';
|
|
|
|
|
|
|
|
jest.mock('path', () => ({
|
|
|
|
__esModule: true,
|
|
|
|
...jest.requireActual('path'),
|
|
|
|
resolve: jest.fn(jest.requireActual('path').resolve),
|
|
|
|
}));
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|