flecks/packages/server/test/runtime-config-bootstrap.js

47 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

import {mkdir} from 'fs/promises';
2024-02-07 15:40:46 -06:00
import {join} from 'path';
import {writeFile} from '@flecks/core/server';
2024-02-05 17:08:26 -06:00
import {expect} from 'chai';
2024-02-14 20:16:31 -06:00
import {withServer} from './helpers/with-server';
2024-02-05 17:08:26 -06:00
2024-02-11 21:03:06 -06:00
it('propagates bootstrap config', withServer(
async ({server}) => {
const [{payload: foo}, {payload: blah}] = await server.actions([
{type: 'config.get', payload: 'server-only.foo'},
{type: 'config.get', payload: 'server-only.blah'},
{type: 'exit'},
]);
expect(foo)
.to.equal('baz');
expect(blah)
.to.deep.equal({one: 2, three: 4});
},
{
beforeBuild: async ({path}) => {
await mkdir(join(path, 'server-only', 'build'), {recursive: true});
await writeFile(join(path, 'server-only', 'package.json'), '{}');
const config = `
exports.hooks = {
'@flecks/core.config': () => ({
foo: 'bar',
blah: {one: 2, three: 4},
}),
};
`;
await writeFile(join(path, 'server-only', 'build', 'flecks.bootstrap.js'), config);
await writeFile(
join(path, 'build', 'flecks.yml'),
`
'@flecks/build': {}
'@flecks/core': {}
'@flecks/server': {}
2024-02-18 10:32:18 -06:00
'server-test:./server-test': {}
2024-02-11 21:03:06 -06:00
'server-only:./server-only': {foo: 'baz'}
`,
);
},
},
));