Skip to content
Permalink
Browse files
fix(core): ArtifactArchiver ensures that the file name works on Windo…
…ws too
  • Loading branch information
jan-molak committed Mar 26, 2019
1 parent 5e4a8c8 commit 7832f0d08220d573864d910abd8dbd246568d00a
@@ -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"
},
@@ -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),
);
});
@@ -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',
);
@@ -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' }),
));

@@ -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'));
});
});
});
@@ -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
@@ -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> {
@@ -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));
@@ -1,4 +1,3 @@
import * as sanitise from 'sanitize-filename';
import { match } from 'tiny-types';

import {
@@ -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',
);
@@ -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',
);
@@ -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+/, '-');
}
}
@@ -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),
));
}

0 comments on commit 7832f0d

Please sign in to comment.