Skip to content

Commit

Permalink
test: actually fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
cha0s committed Feb 12, 2024
1 parent f1c55ad commit 1fecdaf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
9 changes: 8 additions & 1 deletion packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ module.exports = {
if (path !== join(FLECKS_CORE_ROOT, 'build', 'flecks.yml')) {
return;
}
Object.entries(flecks.constructor.dealiasedConfig(config))
const dealiasedConfig = flecks.constructor.dealiasedConfig(config);
if (
JSON.stringify(Object.keys(flecks.originalConfig).sort())
!== JSON.stringify(Object.keys(dealiasedConfig).sort())
) {
throw new Error('build manifest keys changed!');
}
Object.entries(dealiasedConfig)
.forEach(([fleck, value]) => {
if (JSON.stringify(flecks.originalConfig[fleck]) !== JSON.stringify(value)) {
const fleckList = flecks.flecksImplementing('@flecks/core.reload');
Expand Down
3 changes: 1 addition & 2 deletions packages/server/test/server/config-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {withServer} from './build/build';
it('allows updates to fail', withServer(async ({server, socket}) => {
expect((await socket.send({type: 'config.get', payload: 'comm.foo'})).payload)
.to.equal('bar');
const hmr = socket.waitForAction('hmr');
await writeFile(
join(server.path, 'build', 'flecks.yml'),
`
Expand All @@ -18,7 +17,7 @@ it('allows updates to fail', withServer(async ({server, socket}) => {
'comm:./comm': {foo: 'baz'}
`,
);
await hmr;
await socket.waitForAction('hmr');
expect((await socket.send({type: 'config.get', payload: 'comm.foo'})).payload)
.to.equal('baz');
let restarted;
Expand Down
19 changes: 12 additions & 7 deletions packages/server/test/server/template/comm/src/server.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {Flecks} from '@flecks/core';

export const hooks = {
'@flecks/core.reload': (fleck, config) => {
if ('comm' === fleck && 'fail' === config.foo) {
throw new Error();
}
},
'@flecks/core.hmr': async (path, M, flecks) => {
const {socket} = flecks.server;
socket.write(JSON.stringify({
type: 'hmr',
payload: path,
}));
},
'@flecks/core.hmr': Flecks.priority(
async (path, M, flecks) => {
const {socket} = flecks.server;
socket.write(JSON.stringify({
type: 'hmr',
payload: path,
}));
},
{after: '@flecks/core'},
),
};

0 comments on commit 1fecdaf

Please sign in to comment.