Skip to content

Commit

Permalink
issue-8 integrate Windows platform into clean script
Browse files Browse the repository at this point in the history
  • Loading branch information
thomrick committed Aug 5, 2017
1 parent e4a9f94 commit cdf05ba
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
14 changes: 13 additions & 1 deletion scripts/lib/clean.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import {FileSystemUtils} from '../../src/core/utils/file-system.utils';
import * as os from 'os';

export class Clean {
public static execute(args: string[]): Promise<void[]> {
const fileNames: string[] = args.slice(2, args.length);
return Promise.all(fileNames.map(filename => this.clean(filename)));
return Promise.all(
fileNames
.map(filename => this.format(filename))
.map(filename => this.clean(filename)
));
}

private static format(filename: string): string {
if (os.platform() === 'win32')
return filename.replace('*', '');
else
return filename;
}

private static clean(filename: string): Promise<void> {
Expand Down
29 changes: 28 additions & 1 deletion scripts/lib/tests/clean.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as sinon from 'sinon';
import {FileSystemUtils} from '../../../src/core/utils/file-system.utils';
import {Clean} from '../clean';
import * as os from 'os';

describe('Clean', () => {
let sandbox: sinon.SinonSandbox;
Expand All @@ -10,16 +11,22 @@ describe('Clean', () => {
let statStub: sinon.SinonStub;
let rmStub: sinon.SinonStub;
let rmdirStub: sinon.SinonStub;
let platformStub: sinon.SinonStub;
beforeEach(() => {
statStub = sandbox.stub(FileSystemUtils, 'stat');
rmStub = sandbox.stub(FileSystemUtils, 'rm');
rmdirStub = sandbox.stub(FileSystemUtils, 'rmdir');
platformStub = sandbox.stub(os, 'platform');
});

describe('#execute()', () => {
context('should delete all item from argv[1] to the end of argv array', () => {
context('Unix platform', () => {
const argv: string[] = [ 'node_process_call', 'script_call', 'filename1', 'filename2', 'filename3' ];

beforeEach(() => {
platformStub.callsFake(() => 'unix');
});

it('should call stat per file', () => {
statStub.callsFake(() => Promise.resolve({
isFile: () => true
Expand Down Expand Up @@ -60,6 +67,26 @@ describe('Clean', () => {
sinon.assert.calledWith(rmdirStub, 'filename3');
});
});

});

context('win32 platform', () => {
const argv: string[] = [ 'node_process_call', 'script_call', 'directory/*' ];
beforeEach(() => {
platformStub.callsFake(() => 'win32');
rmdirStub.callsFake(() => Promise.resolve());
});

it('should remove * on win32 platform', () => {
statStub.callsFake(() => Promise.resolve({
isFile: () => false
}));

return Clean.execute(argv)
.then(() => {
sinon.assert.calledWith(statStub, 'directory/');
});
});
});
});
});

0 comments on commit cdf05ba

Please sign in to comment.