Skip to content

Commit

Permalink
fix(core): ArtifactArchiver ensures that the file name works on Windo…
Browse files Browse the repository at this point in the history
…ws too
  • Loading branch information
jan-molak committed Mar 26, 2019
1 parent 5e4a8c8 commit 7832f0d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 22 deletions.
1 change: 0 additions & 1 deletion packages/core/package.json
Expand Up @@ -35,7 +35,6 @@
"graceful-fs": "4.1.11",
"mkdirp": "0.5.1",
"moment": "2.22.2",
"sanitize-filename": "1.6.1",
"tiny-types": "1.12.1",
"upath": "^1.1.0"
},
Expand Down
Expand Up @@ -80,7 +80,7 @@ describe('ArtifactArchiver', () => {

return stage.manager.waitForNextCue().then(() => {
expect(fs.store).to.have.been.calledWith(
new Path(`${jsonArtifactName.value}-b283bd69b0fcd75d754f678ac6685786.json`),
new Path(`scenario-report-b283bd69b0fcd75d754f678ac6685786.json`),
JSON.stringify(json),
);
});
Expand All @@ -98,7 +98,7 @@ describe('ArtifactArchiver', () => {

return stage.manager.waitForNextCue().then(() => {
expect(fs.store).to.have.been.calledWith(
new Path(`${pngArtifactName.value}-4fdc8acbf8f6c958b2726fc8ae435bf5.png`),
new Path(`photo-4fdc8acbf8f6c958b2726fc8ae435bf5.png`),
photo.base64EncodedValue,
'base64',
);
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('ArtifactArchiver', () => {
const notifyOf = sinon.spy(stageManager, 'notifyOf');

stageManager.notifyOf(new ArtifactGenerated(
new Name('report'),
new Name('some report name'),
TestReport.fromJSON({ key: 'value' }),
));

Expand All @@ -163,9 +163,9 @@ describe('ArtifactArchiver', () => {
const archived: ArtifactArchived = notifyOf.getCall(2).lastArg;

expect(archived).to.be.instanceOf(ArtifactArchived);
expect(archived.name).to.equal(new Name('report'));
expect(archived.name).to.equal(new Name('some report name'));
expect(archived.type).to.equal(TestReport);
expect(archived.path).to.equal(new Path('report-b283bd69b0fcd75d754f678ac6685786.json'));
expect(archived.path).to.equal(new Path('scenario-report-b283bd69b0fcd75d754f678ac6685786.json'));
});
});
});
4 changes: 2 additions & 2 deletions packages/core/src/stage/StageCrewMember.ts
Expand Up @@ -15,9 +15,9 @@ import { StageManager } from './StageManager';
export abstract class StageCrewMember {

/**
* @param {StageManager} stageManager
* @param {Stage} stage
*/
abstract assignedTo(stageManager: Stage): StageCrewMember;
abstract assignedTo(stage: Stage): StageCrewMember;

/**
* @param {DomainEvent} event
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/stage/StageManager.ts
Expand Up @@ -51,9 +51,7 @@ export class StageManager {
});
this.wip.delete(evt.correlationId);
})
.else(_ => void 0);

this.subscribers.forEach(crewMember => crewMember.notifyOf(event));
.else(_ => this.subscribers.forEach(crewMember => crewMember.notifyOf(event)));
}

waitForNextCue(): Promise<void> {
Expand All @@ -79,7 +77,7 @@ export class StageManager {
let message = `Some of the async operations have failed:\n`;

this.failedOperations.forEach((op: FailedAsyncOperationDetails) => {
message += `${ op.taskDescription.value } - ${ op.error.toString() }\n`;
message += `${ op.taskDescription.value } - ${ op.error.stack }\n---\n`;
});

return reject(new Error(message));
Expand Down
@@ -1,4 +1,3 @@
import * as sanitise from 'sanitize-filename';
import { match } from 'tiny-types';

import {
Expand Down Expand Up @@ -44,7 +43,7 @@ export class ArtifactArchiver implements StageCrewMember {
this.archive(
photo.constructor as ArtifactType,
name,
new Path(`${ this.sanitised(name.value) }-${ this.hashOf(photo) }.png`),
new Path(`photo-${ this.hashOf(photo) }.png`),
photo.base64EncodedValue,
'base64',
);
Expand All @@ -54,7 +53,7 @@ export class ArtifactArchiver implements StageCrewMember {
this.archive(
report.constructor as ArtifactType,
name,
new Path(`${ this.sanitised(name.value) }-${ this.hashOf(report) }.json`),
new Path(`scenario-report-${ this.hashOf(report) }.json`),
report.map(JSON.stringify),
'utf8',
);
Expand Down Expand Up @@ -89,10 +88,4 @@ export class ArtifactArchiver implements StageCrewMember {
this.stage.manager.notifyOf(new AsyncOperationFailed(error, id));
});
}

private sanitised(text: string): string {
return sanitise(text).toLowerCase()
.trim()
.replace(/\s+/, '-');
}
}
Expand Up @@ -52,7 +52,7 @@ export class SerenityBDDReporter implements StageCrewMember {

private broadcast(report: Partial<SerenityBDDReport>) {
this.stage.manager.notifyOf(new ArtifactGenerated(
new Name('scenario-report'),
new Name(report.name),
TestReport.fromJSON(report),
));
}
Expand Down

0 comments on commit 7832f0d

Please sign in to comment.