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-06-08 09:50:25 +00:00
|
|
|
import { existsSync, readdirSync } from 'node:fs';
|
|
|
|
import { dirname, resolve } from 'node:path';
|
|
|
|
import * as pathNode from 'node:path';
|
|
|
|
import { fileURLToPath } from 'node:url';
|
2021-09-30 10:13:13 +00:00
|
|
|
|
2023-06-08 09:50:25 +00:00
|
|
|
import { jest } from '@jest/globals';
|
2021-09-30 10:13:13 +00:00
|
|
|
|
2023-06-08 09:50:25 +00:00
|
|
|
const __dir = fileURLToPath(dirname(import.meta.url));
|
|
|
|
|
|
|
|
jest.unstable_mockModule('node:path', () => ({
|
|
|
|
...pathNode,
|
|
|
|
// spy on resolve to check if a template is referenced
|
|
|
|
resolve: jest.fn(resolve),
|
2021-09-30 10:13:13 +00:00
|
|
|
}));
|
|
|
|
|
2023-06-08 09:50:25 +00:00
|
|
|
const { resolve: resolveSpyed } = await import('node:path');
|
|
|
|
const { loadDynamicMap, resolveContext } = await import('presetter');
|
|
|
|
|
|
|
|
const { default: getPresetAsset } = await import('#index');
|
2021-09-30 10:13:13 +00:00
|
|
|
describe('fn:getPresetAsset', () => {
|
|
|
|
it('use all templates', async () => {
|
2023-06-08 09:50:25 +00:00
|
|
|
const asset = await 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
|
|
|
|
2023-06-08 09:50:25 +00:00
|
|
|
const CONFIGS = resolve(__dir, '..', 'configs');
|
|
|
|
const configs = (existsSync(CONFIGS) && readdirSync(CONFIGS)) || [];
|
|
|
|
const TEMPLATES = resolve(__dir, '..', 'templates');
|
|
|
|
const templates = (existsSync(TEMPLATES) && readdirSync(TEMPLATES)) || [];
|
2021-09-30 10:13:13 +00:00
|
|
|
|
2023-06-08 09:50:25 +00:00
|
|
|
for (const path of configs) {
|
|
|
|
expect(resolveSpyed).toBeCalledWith(CONFIGS, path);
|
2021-09-30 10:13:13 +00:00
|
|
|
}
|
2023-06-08 09:50:25 +00:00
|
|
|
for (const path of templates) {
|
|
|
|
expect(resolveSpyed).toBeCalledWith(TEMPLATES, path);
|
2021-09-30 10:13:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|