Skip to content

Commit 062541b

Browse files
committed
test: add missing tests
1 parent ed89dae commit 062541b

36 files changed

Lines changed: 10573 additions & 1973 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ lib
33
.idea
44
/example/
55
.vscode
6+
/.nyc_output/
7+
/coverage/
8+
/src/tests/e2e/tmp/

.mocharc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require('chai/register-assert'); // Using Assert style
2+
require('chai/register-expect'); // Using Expect style
3+
require('chai/register-should'); // Using Should style

package-lock.json

Lines changed: 9676 additions & 1828 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,30 @@
1010
"lib"
1111
],
1212
"scripts": {
13-
"prepublish": "yarn build && yarn clean",
13+
"commit": "cz",
14+
"test": "nyc ts-mocha --config .mocharc.js --paths -p ./tsconfig.json ./src/tests/unit/**/*.test.ts",
15+
"prepublish": "yarn build",
1416
"postpublish": "yarn build",
1517
"build": "babel src --out-dir lib --copy-files --extensions \".ts\"",
1618
"watch": "yarn build --watch --source-maps inline",
1719
"lint": "eslint src --ext .ts",
18-
"start": "node ./lib/bin.js",
19-
"gen": "node ./lib/__tests__/script.js",
20-
"clean": "rm -rf ./src/__tests__/generated/*; rm -rf ./lib/__tests__"
20+
"start": "node ./lib/bin.js"
21+
},
22+
"nyc": {
23+
"extension": [
24+
".ts",
25+
".tsx"
26+
],
27+
"exclude": [
28+
"src/tests"
29+
],
30+
"include": [
31+
"src"
32+
],
33+
"reporter": [
34+
"html"
35+
],
36+
"all": true
2137
},
2238
"husky": {
2339
"hooks": {
@@ -31,7 +47,10 @@
3147
"@babel/template": "^7.10.4",
3248
"@babel/traverse": "^7.11.0",
3349
"@babel/types": "^7.11.0",
50+
"@types/sinon": "^9.0.10",
51+
"chai": "^4.2.0",
3452
"chalk": "^4.1.0",
53+
"concat-stream": "^2.0.0",
3554
"console-clear": "^1.1.1",
3655
"cosmiconfig": "^6.0.0",
3756
"detect-indent": "^6.0.0",
@@ -41,6 +60,8 @@
4160
"lodash": "^4.17.19",
4261
"log-symbols": "^4.0.0",
4362
"prettier": "^2.0.5",
63+
"sinon": "^9.2.3",
64+
"tsconfig-paths": "^3.9.0",
4465
"yargs": "^15.4.1"
4566
},
4667
"devDependencies": {
@@ -53,17 +74,29 @@
5374
"@types/babel-traverse": "^6.25.5",
5475
"@types/babel-types": "^7.0.8",
5576
"@types/babel__generator": "^7.6.1",
77+
"@types/chai": "^4.2.14",
78+
"@types/concat-stream": "^1.6.0",
79+
"@types/expect": "^24.3.0",
5680
"@types/fs-extra": "^9.0.1",
5781
"@types/inquirer": "^6.5.0",
82+
"@types/mocha": "^8.2.0",
5883
"@types/yargs": "^15.0.5",
5984
"@typescript-eslint/eslint-plugin": "^3.9.0",
6085
"@typescript-eslint/parser": "^3.9.0",
6186
"babel-plugin-module-resolver": "^4.0.0",
87+
"commitizen": "^4.2.3",
88+
"cz-conventional-changelog": "^3.3.0",
6289
"eslint": "^6.8.0",
6390
"eslint-config-airbnb-base": "^14.2.0",
6491
"eslint-config-airbnb-typescript": "^8.0.2",
6592
"eslint-config-prettier": "^6.11.0",
6693
"eslint-plugin-import": "^2.22.0",
94+
"execa": "^5.0.0",
95+
"mocha": "^8.2.1",
96+
"nyc": "^15.1.0",
97+
"proxyquire": "^2.1.3",
98+
"semantic-release": "^17.3.2",
99+
"ts-mocha": "^8.0.0",
67100
"typescript": "^3.9.7"
68101
},
69102
"keywords": [
@@ -77,5 +110,10 @@
77110
],
78111
"repository": "https://github.com/Cristians953/react-codegen-cli.git",
79112
"author": "Cristian Vasiliev <vasiliev.cristian99@gmail.com>",
80-
"license": "MIT"
113+
"license": "MIT",
114+
"config": {
115+
"commitizen": {
116+
"path": "./node_modules/cz-conventional-changelog"
117+
}
118+
}
81119
}

src/__tests__/answers.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/__tests__/config.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/__tests__/script.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/bin.ts

100644100755
File mode changed.

src/config/Config.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ export class Config implements IConfig {
4242

4343
exportType: ExportType;
4444

45+
userConfig: IConfig;
46+
4547
constructor(config: IConfig) {
46-
const cfg = Object.assign(DEFAULT_CONFIG, config);
48+
this.userConfig = config;
49+
const cfg = { ...DEFAULT_CONFIG, ...config };
4750

4851
this.setVariables(cfg);
4952
this.setFilesExtension();
@@ -99,19 +102,18 @@ export class Config implements IConfig {
99102

100103
// Other
101104

102-
this.path = path.resolve(APP_ROOT, config.path ?? DEFAULT_CONFIG.path);
105+
if (!this.path || config.path) {
106+
this.path = path.resolve(APP_ROOT, config.path ?? DEFAULT_CONFIG.path);
107+
}
103108
}
104109

105110
private setFilesExtension() {
106-
let styleExt = this.styles.toLowerCase();
107-
if (styleExt === 'stylus') {
108-
styleExt = 'styl';
109-
}
111+
const styleExt = this.styles.toLowerCase();
110112

111113
this.ext = {
112114
component: this.typescript ? 'tsx' : `j${this.jsxExt ? 'sx' : 's'}`,
113115
script: `${this.typescript ? 't' : 'j'}s`,
114-
style: styleExt,
116+
style: styleExt === 'stylus' ? 'styl' : styleExt,
115117
};
116118
}
117119

@@ -122,9 +124,13 @@ export class Config implements IConfig {
122124
};
123125
}
124126

125-
public update(config: IConfig) {
127+
public update(config: Partial<IConfig>) {
126128
this.setVariables(config);
127129
this.setFilesExtension();
128130
this.setPrefixes();
129131
}
132+
133+
public reset() {
134+
this.update({ ...DEFAULT_CONFIG, ...this.userConfig });
135+
}
130136
}

src/constants/index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { ExportType, IConfig, StyleFormats } from '@/types';
2-
import * as utils from '@/utils';
2+
// import { getAppRoot } from '@/utils';
3+
import findUp from 'find-up';
4+
import path from 'path';
5+
import { Logger } from '@/core/Logger';
36

47
export const DEFAULT_CONFIG: IConfig = {
58
styles: 'scss',
@@ -12,12 +15,28 @@ export const DEFAULT_CONFIG: IConfig = {
1215
exportType: 'default',
1316
arrowFunction: true,
1417
};
18+
1519
export const STYLE_FORMATS: StyleFormats[] = [
1620
'css',
1721
'scss',
1822
'sass',
1923
'less',
2024
'stylus',
2125
];
26+
2227
export const EXPORT_TYPES: ExportType[] = ['named', 'default'];
23-
export const APP_ROOT = utils.getAppRoot();
28+
29+
/* istanbul ignore next */
30+
export const APP_ROOT = (() => {
31+
const file = findUp.sync('package.json');
32+
33+
if (file) {
34+
return path.dirname(file);
35+
}
36+
37+
Logger.warn(
38+
'Could not find application root. Files will be generated relative to the current directory'
39+
);
40+
41+
return process.cwd();
42+
})();

0 commit comments

Comments
 (0)