test: yml

This commit is contained in:
cha0s 2024-02-04 17:07:13 -06:00
parent bd143df524
commit b0dbc59f6d
2 changed files with 19 additions and 2 deletions

View File

@ -7,8 +7,8 @@ const {
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
module.exports = async (paths) => {
const ymlPath = join(FLECKS_CORE_ROOT, 'build', 'flecks.yml');
module.exports = async (paths, root) => {
const ymlPath = join(root || FLECKS_CORE_ROOT, 'build', 'flecks.yml');
let yml = loadYml(await readFile(ymlPath));
yml = Object.fromEntries(Object.entries(yml).concat(paths.map((path) => [path, {}])));
await writeFile(ymlPath, dumpYml(yml, {sortKeys: true}));

View File

@ -0,0 +1,17 @@
import {readFile, writeFile} from 'fs/promises';
import {load as loadYml} from 'js-yaml';
import addPathsToYml from '@flecks/build/build/add-paths-to-yml';
import {expect} from 'chai';
it('can add paths to YML', async () => {
await writeFile(
'test/server/yml/build/flecks.yml',
`
bar: {}
foo: {}
`,
);
await addPathsToYml(['a', 'two'], 'test/server/yml');
expect(Object.keys(await loadYml(await readFile('test/server/yml/build/flecks.yml'))))
.to.deep.equal(['a', 'bar', 'foo', 'two']);
});