Skip to content

Commit a9f19af

Browse files
clydinfilipesilva
authored andcommitted
test: convert helpers to typescript
1 parent b24c9cf commit a9f19af

File tree

4 files changed

+24
-34
lines changed

4 files changed

+24
-34
lines changed

tests/helpers/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
const ng: ((parameters: string[]) => Promise<any>) = require('./ng');
2-
const tmp = require('./tmp');
1+
import { ng } from './ng';
2+
import { setup, teardown } from './tmp';
3+
4+
export { ng };
35

46
export function setupProject() {
57
beforeEach((done) => {
68
spyOn(console, 'error');
79

8-
tmp.setup('./tmp')
10+
setup('./tmp')
911
.then(() => process.chdir('./tmp'))
1012
.then(() => ng(['new', 'foo', '--skip-install']))
1113
.then(done, done.fail);
1214
}, 10000);
1315

1416
afterEach((done) => {
15-
tmp.teardown('./tmp').then(done, done.fail);
17+
teardown('./tmp').then(done, done.fail);
1618
});
1719
}
18-
19-
export {
20-
ng
21-
};

tests/helpers/ng.js

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
'use strict';
2-
1+
import cli from '@angular/cli/lib/cli';
32
const UI = require('@angular/cli/ember-cli/lib/ui');
43
const through = require('through');
54

6-
module.exports = MockUI;
75
function MockUI() {
86
this.output = '';
97

108
UI.call(this, {
119
inputStream: through(),
12-
outputStream: through(function (data) {
10+
outputStream: through(function (data: any) {
1311
this.output += data;
1412
}.bind(this)),
15-
errorStream: through(function (data) {
13+
errorStream: through(function (data: any) {
1614
this.errors += data;
1715
}.bind(this))
1816
});
@@ -23,3 +21,15 @@ MockUI.prototype.constructor = MockUI;
2321
MockUI.prototype.clear = function () {
2422
this.output = '';
2523
};
24+
25+
export function ng(args: any) {
26+
process.env.PWD = process.cwd();
27+
28+
return cli({
29+
inputStream: [],
30+
outputStream: [],
31+
cliArgs: args,
32+
UI: MockUI,
33+
testing: true
34+
});
35+
}

tests/helpers/tmp.js renamed to tests/helpers/tmp.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
'use strict';
2-
3-
const fs = require('fs-extra');
1+
import * as fs from 'fs-extra';
42

53
const root = process.cwd();
64

7-
module.exports.setup = function (path) {
5+
export function setup(path: string) {
86
process.chdir(root);
97

108
return fs.remove(path).then(function () {
119
fs.mkdirsSync(path);
1210
});
1311
};
1412

15-
module.exports.teardown = function (path) {
13+
export function teardown(path: string) {
1614
process.chdir(root);
1715

1816
if (fs.pathExistsSync(path)) {

0 commit comments

Comments
 (0)