Skip to content
Permalink
Browse files
feat(core): ArtifactArchiver can be instantiated using a convenient f…
…actory method
  • Loading branch information
jan-molak committed May 1, 2019
1 parent 0d4faab commit 6716f5f2ab0a2d7c418df052380e6b25900dd5b4
@@ -170,4 +170,16 @@ describe('ArtifactArchiver', () => {
expect(archived.path).to.equal(new Path('scenario-report-b283bd69b0fcd75d754f678ac6685786.json'));
});
});

describe('when instantiated using a factory method', () => {
it(`joins the path segments provided so that the developer doesn't need to worry about cross-OS compatibility of the path`, () => {
archiver = ArtifactArchiver.storingArtifactsAt(process.cwd(), 'target', 'site/serenity');

expect((archiver as any).fileSystem.root).to.equal(new Path(process.cwd()).join(new Path('target/site/serenity')));
});

it(`complains if the destination is not provided`, () => {
expect(() => ArtifactArchiver.storingArtifactsAt()).to.throw(Error, 'Path to destination directory should have length that is greater than 0');
});
});
});
@@ -1,3 +1,4 @@
import { ensure, isGreaterThan, property } from 'tiny-types';
import {
ActivityRelatedArtifactArchived,
ActivityRelatedArtifactGenerated,
@@ -21,6 +22,14 @@ import { MD5Hash } from './MD5Hash';
*/
export class ArtifactArchiver implements StageCrewMember {

static storingArtifactsAt(...destination: string[]): ArtifactArchiver {
ensure('Path to destination directory', destination, property('length', isGreaterThan(0)));

const pathToDestination = destination.map(segment => new Path(segment)).reduce((acc, current) => acc.join(current));

return new ArtifactArchiver(new FileSystem(pathToDestination));
}

constructor(
private readonly fileSystem: FileSystem,
private readonly stage: Stage = null,
@@ -107,4 +116,4 @@ export class ArtifactArchiver implements StageCrewMember {
}
};
}
}
}

0 comments on commit 6716f5f

Please sign in to comment.