Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 5cc69d1

Browse files
authored
test: switch to ava (#222)
1 parent deb47a7 commit 5cc69d1

File tree

5 files changed

+395
-376
lines changed

5 files changed

+395
-376
lines changed

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"build": "tsc --sourceMap",
1919
"build:inline": "tsc --inlineSourceMap",
2020
"pretest": "npm run clean && npm run build:inline",
21-
"test": "nyc --all --reporter lcov ./node_modules/.bin/mocha --require source-map-support --recursive dist/tests/*-test.js",
21+
"test": "nyc --all --reporter lcov ./node_modules/.bin/ava",
2222
"coverage": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
2323
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -w",
2424
"prerelease": "npm test && npm run build",
@@ -35,24 +35,21 @@
3535
},
3636
"license": "MIT",
3737
"devDependencies": {
38-
"@types/chai": "3.4.34",
3938
"@types/chalk": "0.4.31",
4039
"@types/diff": "0.0.31",
41-
"@types/mocha": "2.2.32",
4240
"@types/node": "6.0.46",
4341
"@types/react": "0.14.44",
42+
"ava": "0.16.0",
4443
"babel-core": "6.18.2",
4544
"babel-preset-es2015": "6.18.0",
4645
"babel-register": "6.18.0",
47-
"chai": "3.5.0",
4846
"chalk": "1.1.3",
4947
"chokidar-cli": "1.2.0",
5048
"conventional-changelog-cli": "1.2.0",
5149
"coveralls": "2.11.14",
5250
"cz-conventional-changelog": "1.2.0",
5351
"diff": "3.0.1",
5452
"in-publish": "2.0.0",
55-
"mocha": "3.1.2",
5653
"nyc": "8.4.0",
5754
"react": "15.3.2",
5855
"rimraf": "2.5.4",
@@ -73,6 +70,17 @@
7370
"path": "./node_modules/cz-conventional-changelog"
7471
}
7572
},
73+
"ava": {
74+
"files": [
75+
"dist/tests/**/*-test.js"
76+
],
77+
"source": [
78+
"dist/src/**/*.js"
79+
],
80+
"require": [
81+
"source-map-support"
82+
]
83+
},
7684
"nyc": {
7785
"exclude": [
7886
"node_modules",

tests/generator-test.ts

Lines changed: 82 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,94 @@
1-
import { assert } from 'chai';
1+
import test from 'ava';
2+
23
import { Generator } from '../src/generator';
34
import { generateFromSource } from '../src/index';
45

5-
describe('The Generator', () => {
6-
let generator: Generator;
7-
beforeEach(() => {
8-
generator = new Generator();
9-
});
10-
it('should write a module declaration', () => {
11-
generator.declareModule('name', () => {
12-
//
13-
});
14-
assert.equal(generator.toString(), "declare module 'name' {\n}\n");
15-
});
16-
it('should write an import statement', () => {
17-
generator.import('decls', 'from');
18-
assert.equal(generator.toString(), "import decls from 'from';\n");
19-
});
20-
it('should write a required property', () => {
21-
generator.prop('name', 'type', false);
22-
assert.equal(generator.toString(), 'name: type;\n');
23-
});
24-
it('should write an optional property', () => {
25-
generator.prop('name', 'type', true);
26-
assert.equal(generator.toString(), 'name?: type;\n');
27-
});
28-
it('should write a property interface', () => {
29-
generator.props('Name', {prop: {type: 'type', optional: true}});
30-
assert.equal(generator.toString(), 'export interface NameProps {\n\tprop?: type;\n}\n');
31-
});
32-
it('should write a class with props declaration', () => {
33-
generator.class('Name', true);
34-
assert.equal(generator.toString(), 'class Name extends React.Component<NameProps, any> {\n}\n');
35-
});
36-
it('should write a class without props declaration', () => {
37-
generator.class('Name', false);
38-
assert.equal(generator.toString(), 'class Name extends React.Component<any, any> {\n}\n');
39-
});
40-
it('should write an indented block comment', () => {
41-
generator.comment('* yada\n\t\t\t\tyada\n ');
42-
assert.equal(generator.toString(), '/** yada\nyada\n */\n');
43-
});
44-
it('should write an export default declaration', () => {
45-
generator.exportDeclaration(0, () => undefined);
46-
assert.equal(generator.toString(), 'export default ');
47-
});
48-
it('should write a named export declaration', () => {
49-
generator.exportDeclaration(1, () => undefined);
50-
assert.equal(generator.toString(), 'export ');
51-
});
52-
});
53-
54-
describe('Generating typings with given custom generator', () => {
55-
let generator: Generator;
6+
function setup(): Generator {
7+
return new Generator();
8+
}
569

57-
beforeEach(() => {
58-
generator = new Generator();
10+
test('The Generator should write a module declaration', t => {
11+
const generator = setup();
12+
generator.declareModule('name', () => {
13+
//
5914
});
15+
t.is(generator.toString(), "declare module 'name' {\n}\n");
16+
});
17+
test('The Generator should write an import statement', t => {
18+
const generator = setup();
19+
generator.import('decls', 'from');
20+
t.is(generator.toString(), "import decls from 'from';\n");
21+
});
22+
test('The Generator should write a required property', t => {
23+
const generator = setup();
24+
generator.prop('name', 'type', false);
25+
t.is(generator.toString(), 'name: type;\n');
26+
});
27+
test('The Generator should write an optional property', t => {
28+
const generator = setup();
29+
generator.prop('name', 'type', true);
30+
t.is(generator.toString(), 'name?: type;\n');
31+
});
32+
test('The Generator should write a property interface', t => {
33+
const generator = setup();
34+
generator.props('Name', {prop: {type: 'type', optional: true}});
35+
t.is(generator.toString(), 'export interface NameProps {\n\tprop?: type;\n}\n');
36+
});
37+
test('The Generator should write a class with props declaration', t => {
38+
const generator = setup();
39+
generator.class('Name', true);
40+
t.is(generator.toString(), 'class Name extends React.Component<NameProps, any> {\n}\n');
41+
});
42+
test('The Generator should write a class without props declaration', t => {
43+
const generator = setup();
44+
generator.class('Name', false);
45+
t.is(generator.toString(), 'class Name extends React.Component<any, any> {\n}\n');
46+
});
47+
test('The Generator should write an indented block comment', t => {
48+
const generator = setup();
49+
generator.comment('* yada\n\t\t\t\tyada\n ');
50+
t.is(generator.toString(), '/** yada\nyada\n */\n');
51+
});
52+
test('The Generator should write an export default declaration', t => {
53+
const generator = setup();
54+
generator.exportDeclaration(0, () => undefined);
55+
t.is(generator.toString(), 'export default ');
56+
});
57+
test('The Generator should write a named export declaration', t => {
58+
const generator = setup();
59+
generator.exportDeclaration(1, () => undefined);
60+
t.is(generator.toString(), 'export ');
61+
});
6062

61-
it('should delare a module if name given', () => {
62-
let name: string|undefined;
63-
generator.declareModule = moduleName => {
64-
name = moduleName;
65-
};
63+
test('Generating typings with given custom generator should delare a module if name given', t => {
64+
const generator = setup();
65+
let name: string|undefined;
66+
generator.declareModule = moduleName => {
67+
name = moduleName;
68+
};
6669

67-
const source = `
68-
export class Test {}
69-
`;
70-
generateFromSource('module', source, {generator});
70+
const source = `
71+
export class Test {}
72+
`;
73+
generateFromSource('module', source, {generator});
7174

72-
assert.equal(name, 'module');
73-
});
75+
t.is(name, 'module');
76+
});
7477

75-
it('should import react', () => {
76-
let decl: string|undefined;
77-
let from: string|undefined;
78-
generator.import = (_decl, _from) => {
79-
decl = _decl;
80-
from = _from;
81-
};
78+
test('Generating typings with given custom generator should import react', t => {
79+
const generator = setup();
80+
let decl: string|undefined;
81+
let from: string|undefined;
82+
generator.import = (_decl, _from) => {
83+
decl = _decl;
84+
from = _from;
85+
};
8286

83-
const source = `
84-
export class Test {}
85-
`;
86-
generateFromSource(null, source, {generator});
87+
const source = `
88+
export class Test {}
89+
`;
90+
generateFromSource(null, source, {generator});
8791

88-
assert.equal(decl, '* as React');
89-
assert.equal(from, 'react');
90-
});
92+
t.is(decl, '* as React');
93+
t.is(from, 'react');
9194
});

0 commit comments

Comments
 (0)