Skip to content

Commit b33c02f

Browse files
authored
test(usage): adding test for specific case (#46)
1 parent f13725d commit b33c02f

File tree

8 files changed

+71
-22
lines changed

8 files changed

+71
-22
lines changed

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@
3131
},
3232
"homepage": "https://github.com/TypeScript-Heroes/node-typescript-parser#readme",
3333
"devDependencies": {
34-
"@types/jest": "^21.1.0",
34+
"@types/jest": "^21.1.8",
3535
"@types/mock-fs": "^3.6.30",
36-
"@types/node": "^8.0.31",
36+
"@types/node": "^8.0.57",
3737
"del-cli": "^1.1.0",
38-
"jest": "^21.2.0",
39-
"mock-fs": "^4.4.1",
38+
"jest": "^21.2.1",
39+
"mock-fs": "^4.4.2",
4040
"semantic-release": "^9.0.0",
41-
"ts-jest": "^21.0.0",
42-
"tslint": "^5.5.0",
43-
"tslint-config-airbnb": "^5.2.1",
44-
"tsutils": "^2.9.0",
45-
"typedoc": "^0.8.0"
41+
"ts-jest": "^21.2.4",
42+
"tslint": "^5.8.0",
43+
"tslint-config-airbnb": "^5.4.2",
44+
"tsutils": "^2.13.0",
45+
"typedoc": "^0.9.0"
4646
},
4747
"dependencies": {
4848
"lodash": "^4.17.4",
49-
"tslib": "^1.7.1",
50-
"typescript": "^2.5.3"
49+
"tslib": "^1.8.1",
50+
"typescript": "^2.6.2"
5151
}
5252
}

src/code-generators/typescript-generators/namedImport.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function specifierSort(i1: SymbolSpecifier, i2: SymbolSpecifier): number {
2323

2424
if (strA < strB) {
2525
return -1;
26-
} else if (strA > strB) {
26+
}
27+
if (strA > strB) {
2728
return 1;
2829
}
2930
return 0;

src/resources/Module.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Resource } from './Resource';
77

88
/**
99
* TypeScript resource. Declaration of a typescript module (i.e. declare module "foobar").
10-
*
10+
*
1111
* @export
1212
* @class Module
1313
* @implements {Resource}
@@ -39,19 +39,18 @@ export class Module implements Resource, Node {
3939
/**
4040
* Function that calculates the alias name of a namespace.
4141
* Removes all underlines and dashes and camelcases the name.
42-
*
42+
*
4343
* @returns {string}
44-
*
44+
*
4545
* @memberof Module
4646
*/
4747
public getNamespaceAlias(): string {
4848
return this.name.split(/[-_]/).reduce(
4949
(all, cur, idx) => {
5050
if (idx === 0) {
5151
return all + cur.toLowerCase();
52-
} else {
53-
return all + cur.charAt(0).toUpperCase() + cur.substring(1).toLowerCase();
5452
}
53+
return all + cur.charAt(0).toUpperCase() + cur.substring(1).toLowerCase();
5554
},
5655
'',
5756
);

src/resources/Namespace.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Resource } from './Resource';
77

88
/**
99
* TypeScript resource. Declaration of a typescript namespace (i.e. declare foobar).
10-
*
10+
*
1111
* @export
1212
* @class Namespace
1313
* @implements {Resource}
@@ -39,19 +39,18 @@ export class Namespace implements Resource, Node {
3939
/**
4040
* Function that calculates the alias name of a namespace.
4141
* Removes all underlines and dashes and camelcases the name.
42-
*
42+
*
4343
* @returns {string}
44-
*
44+
*
4545
* @memberof Namespace
4646
*/
4747
public getNamespaceAlias(): string {
4848
return this.name.split(/[-_]/).reduce(
4949
(all, cur, idx) => {
5050
if (idx === 0) {
5151
return all + cur.toLowerCase();
52-
} else {
53-
return all + cur.charAt(0).toUpperCase() + cur.substring(1).toLowerCase();
5452
}
53+
return all + cur.charAt(0).toUpperCase() + cur.substring(1).toLowerCase();
5554
},
5655
'',
5756
);

test/SpecificUsageCases.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { TypescriptParser } from '../src';
2+
import { getWorkspaceFile, rootPath } from './testUtilities';
3+
4+
describe('Specific usage cases', () => {
5+
const parser = new TypescriptParser();
6+
7+
describe('i18next with and without destructure', () => {
8+
9+
it('should contain i18next reference in not destructured way', async () => {
10+
const file = getWorkspaceFile('specific-usage-cases/i18next-destructure/import-my-component.tsx');
11+
const parsed = await parser.parseFile(file, rootPath);
12+
expect(parsed.usages).toMatchSnapshot();
13+
});
14+
15+
it('should contain t reference in destructured way', async () => {
16+
const file = getWorkspaceFile('specific-usage-cases/i18next-destructure/destructure-my-component.tsx');
17+
const parsed = await parser.parseFile(file, rootPath);
18+
expect(parsed.usages).toMatchSnapshot();
19+
});
20+
21+
});
22+
23+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Specific usage cases i18next with and without destructure should contain i18next reference in not destructured way 1`] = `
4+
Array [
5+
"MyComponent",
6+
"p",
7+
"i18next",
8+
]
9+
`;
10+
11+
exports[`Specific usage cases i18next with and without destructure should contain t reference in destructured way 1`] = `
12+
Array [
13+
"MyComponent",
14+
"p",
15+
"t",
16+
]
17+
`;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from 'react';
2+
import { t } from 'i18next';
3+
4+
export const MyComponent = () => (
5+
<p>{t('foo')}</p>
6+
);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as i18next from 'i18next';
2+
import * as React from 'react';
3+
4+
export const MyComponent = () => <p>{i18next.t('foo')}</p>;

0 commit comments

Comments
 (0)