Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading configs from .env with dotenv #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JEST_TEST_GEN_FILESUFFIX=".spec"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ lib/
jasmine-unit-test-generator-*.tgz
.npmrc
.DS_Store
.env
.yarn
**/yarn-error.log
**/yarn.lock
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"dependencies": {
"compare-versions": "^4.1.3",
"debug": "4.3.2",
"dotenv": "^16.0.3",
"latest-version": "^5.1.0",
"lodash": "^4.1.*",
"minimist": "^1.2.6",
Expand Down
9 changes: 7 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
export const MOCK_MODULES_BLACKLIST = ['react', 'prop-types', 'styled-components'];
export const IMPORT_MODULES_BLACKLIST = ['prop-types', 'styled-components'];
export const FILE_SUFFIX = process.env.JEST_TEST_GEN_FILESUFFIX;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a constant, it is a configuration, no need to read the config inside this file, it can be done in main.ts

export const MOCK_MODULES_BLACKLIST = [
'react',
'prop-types',
'styled-components',
];
export const IMPORT_MODULES_BLACKLIST = ['prop-types', 'styled-components'];
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as ts from 'typescript';
import { parseSourceFile } from './parse-source-file';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here the should be an import of dotenv at the top to make it work

import * as dotenv from 'dotenv'
dotenv.config()

import { generateUnitTest } from './generate-unit-test';
import * as minimist from 'minimist';
import { FILE_SUFFIX } from './constants';

type TRunOptions = {
returnOutput?: boolean
Expand Down Expand Up @@ -32,7 +33,7 @@ export function run(args: minimist.ParsedArgs, opts?: TRunOptions) {
finalOutputDir = path.resolve(finalOutputDir, args.outputDir);
}
}
let fileSuffix = '.generated.test';
let fileSuffix = FILE_SUFFIX;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep the default and if specified, override with the process.env.value and finally any command line arguments have priority.
eg:

let fileSuffix = '.generated.test';
if (process.env.JEST_TEST_GEN_FILESUFFIX) {
    fileSuffix = process.env.JEST_TEST_GEN_FILESUFFIX;
 }
if (args.fileSuffix) {
    fileSuffix = args.fileSuffix;
 }

if (args.fileSuffix) {
fileSuffix = args.fileSuffix;
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"dom"
]
}
}
}