Skip to content

Commit

Permalink
debug broken unit tests on github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
youngbryanyu committed Jan 16, 2024
1 parent d13bb1e commit 1584192
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 55 deletions.
3 changes: 0 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<!-- Ignore JS artifact/build files -->
**/dist

<!-- Ignore Test files -->
**/tests

<!-- Ignore javascript files -->
**/**.js
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/* See .eslintignore for rules */
],
"rules": {
// "no-console": 2, /* Don't allow console statements */
"no-console": 2, /* Don't allow console statements */
"prettier/prettier": 2 /* Check if format matches prettier */
}
}
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ignore .env files, but push those in testing folder
/.env**
!/testing/.env**
!/testing/.env**

# ignore node_modules
node_modules
Expand All @@ -15,5 +15,11 @@ node_modules
/config
!/testing/config

# ignore testing packed npm modules
simple-app-config-**.tgz
# ignore testing packed tar ball npm modules
simple-app-config-**.tgz

# ignore manual testing folder
manualTesting

# ignore DS store
.DS_Store
3 changes: 0 additions & 3 deletions src/simple-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,6 @@ export class Config {
private static loadConfigFile(path: string | undefined): void {
/* Reset any previous values in the config file */
Config.configMap.clear();
console.log('clearing config map');
console.log(Config.configMap);
console.log('cone clearing config map');

if (path !== undefined) {
Config.parseConfigIntoMap(path);
Expand Down
2 changes: 1 addition & 1 deletion tests/.env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ SET = '[1, 2, 3]'
MAP = '{"cat": "test", "bat": "test"}'
MAP2 = '{"cat": {"test": {"test": [1, 2, 3]}}, "bat": 5}'
OBJECT = '{"bat": 5}'
ENV = TESTING
ENV = TESTING
28 changes: 2 additions & 26 deletions tests/config/development.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
{
"ENV": "$ENV",
"var1": {
"var2": {
"var3": "$MAP::map"
}
},
"test": {
"array": [
1,
2,
{
"nested": "map"
}
]
},
"nested": {
"test": "${MAP}"
},
"array": [
"${ENV} hi",
true,
{
"test": "$MAP::map:string:string"
}
]
}
"ENV": "$ENV"
}
27 changes: 9 additions & 18 deletions tests/simple-app-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* Unit tests for env-var-config */
import { existsSync } from 'fs';
import { CommandLineArgs, EnvArgs } from '../src/constants';
import { UndefinedConfigValueError } from '../src/errors/undefinedConfigValueError';
import { UndefinedEnvVarError } from '../src/errors/undefinedEnvVarError';
import { UnsupportedTypeError } from '../src/errors/unsupportedTypeError';
import Config, { EnvParser } from '../src/index';
import sinon from 'ts-sinon';
Expand All @@ -25,7 +23,7 @@ describe('simple-app-config Tests', () => {
process.env[EnvArgs.EnvNames] = 'development,testing,staging,production';
Config.configure({ force: true });

/* Reset all environment variables */
/* Reset all environment variables. Keep in mind this resets all env vars if .configure is called again manually within the test itself. */
for (const key in process.env) {
delete process.env[key];
}
Expand All @@ -37,6 +35,7 @@ describe('simple-app-config Tests', () => {
it('should get a value successfully from the config file if it exists', () => {
/* Set up */
const key = 'ENV';

const result = Config.get(key);

/* Compare against expected */
Expand Down Expand Up @@ -242,32 +241,24 @@ describe('simple-app-config Tests', () => {
it('should be able to set the environment with command line args and override lesser priority values.', () => {
sinon.stub(process, 'argv').value([`${CommandLineArgs.Env}development`]);
process.env[EnvArgs.Env] = 'production';
process.env[EnvArgs.ConfigDir] = `${__dirname}`;
process.env[EnvArgs.EnvDir] = `${__dirname}`;
Config.configure({ force: true });
expect(Config.get('ENV')).toBe('DEVELOPMENT');
});

/* Test setting .env path with environment variable */
it('should be able to set the .env path with environment variables.', () => {
process.env[EnvArgs.EnvPath] = `${__dirname}/.env.production`;
process.env[EnvArgs.ConfigDir] = `${__dirname}`;
Config.configure({ force: true });
console.log(existsSync(`${__dirname}/.env.production`));
console.log(`${__dirname}/.env.production`);
console.log(Config.environments);
console.log(Config.envPaths);
console.log(Config.configPaths);
console.log(process.cwd());
console.log(Config.environment);
console.log(Config.configMap);
console.log(process.env);
console.log(Config.get('ENV'));

expect(Config.get('ENV')).toBe('PRODUCTION');
});

/* Test setting .env path with command line argument */
it('should be able to set the .env path with command line arguments, and have it override lower priority values', () => {
sinon.stub(process, 'argv').value([`${CommandLineArgs.EnvPath}.env.production`]);
// process.env[EnvArgs.ConfigPath] = `${__dirname}/config/beta.json`;
sinon.stub(process, 'argv').value([`${CommandLineArgs.EnvPath}${__dirname}/.env.production`]);
process.env[EnvArgs.ConfigPath] = `${__dirname}/config/development.json`;
process.env[EnvArgs.EnvPath] = `${__dirname}/.env.development`;
Config.configure({ force: true });
expect(Config.get('ENV')).toBe('PRODUCTION');
Expand All @@ -279,9 +270,9 @@ describe('simple-app-config Tests', () => {
.stub(process, 'argv')
.value([
`${CommandLineArgs.Env}INVALID_ENV`,
`${CommandLineArgs.ConfigPath}config/development.json`
`${CommandLineArgs.ConfigPath}${__dirname}/config/development.json`
]);
expect(() => Config.configure({ force: true })).toThrow(UndefinedEnvVarError);
expect(() => Config.configure({ force: true })).toThrow(Error);
});

/* Test setting config path with environment variable */
Expand Down

0 comments on commit 1584192

Please sign in to comment.