Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/execution/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,7 @@ export class ServiceScriptExecution extends BaseExecutionWithCommand<ServiceScri
private _onChildExited() {
switch (this._state.id) {
case 'stopping': {
this._state = {
id: 'stopped',
};
this._terminated.resolve({ok: true, value: undefined});
this._servicesNotNeeded.resolve();
this._enterStoppedState();
this._logger.log({
script: this._config,
type: 'info',
Expand All @@ -697,15 +693,15 @@ export class ServiceScriptExecution extends BaseExecutionWithCommand<ServiceScri
return;
}
case 'started': {
this._fail({
this._enterFailedState({
script: this._config,
type: 'failure',
reason: 'service-exited-unexpectedly',
});
return;
}
case 'failing': {
this._fail(this._state.failure);
this._enterFailedState(this._state.failure);
return;
}
case 'failed':
Expand Down Expand Up @@ -745,7 +741,7 @@ export class ServiceScriptExecution extends BaseExecutionWithCommand<ServiceScri
case 'stoppingAdoptee':
case 'unstarted':
case 'depsStarting': {
this._state = {id: 'stopped'};
this._enterStoppedState();
return;
}
case 'stopping':
Expand All @@ -761,7 +757,13 @@ export class ServiceScriptExecution extends BaseExecutionWithCommand<ServiceScri
}
}

private _fail(failure: Failure) {
private _enterStoppedState() {
this._state = {id: 'stopped'};
this._terminated.resolve({ok: true, value: undefined});
this._servicesNotNeeded.resolve();
}

private _enterFailedState(failure: Failure) {
this._state = {
id: 'failed',
failure,
Expand Down
74 changes: 74 additions & 0 deletions src/test/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,4 +823,78 @@ test(
})
);

test(
'caching with service dependencies works in watch mode',
timeout(async ({rig}) => {
// consumer
// |
// v
// service

const consumer = await rig.newCommand();
const service = await rig.newCommand();
await rig.writeAtomic({
'package.json': {
scripts: {
consumer: 'wireit',
service: 'wireit',
},
wireit: {
consumer: {
command: consumer.command,
dependencies: ['service'],
files: [],
output: [],
},
service: {
command: service.command,
service: true,
files: ['input'],
},
},
},
});

await rig.write('input', 'A');
const wireit = rig.exec('npm run consumer --watch');

// 1st run with input A. Runs.
{
const serviceInv = await service.nextInvocation();
const consumerInv1 = await consumer.nextInvocation();
consumerInv1.exit(0);
await serviceInv.closed;
await wireit.waitForLog(/Watching for file changes/);
assert.equal(service.numInvocations, 1);
assert.equal(consumer.numInvocations, 1);
}

// 2nd run with input B. Runs.
{
await rig.write('input', 'B');
const serviceInv = await service.nextInvocation();
const consumerInv1 = await consumer.nextInvocation();
consumerInv1.exit(0);
await serviceInv.closed;
await wireit.waitForLog(/Watching for file changes/);
assert.equal(service.numInvocations, 2);
assert.equal(consumer.numInvocations, 2);
}

// 3rd run with input A. Restored from cache.
{
await rig.write('input', 'A');
await wireit.waitForLog(/Restored from cache/);
await wireit.waitForLog(/Watching for file changes/);
assert.equal(service.numInvocations, 2);
assert.equal(consumer.numInvocations, 2);
}

wireit.kill();
await wireit.exit;
assert.equal(service.numInvocations, 2);
assert.equal(consumer.numInvocations, 2);
})
);

test.run();