Skip to content

Commit

Permalink
test: return dotenv-safe back to wallet and sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
markin-io committed Oct 2, 2023
1 parent d889fab commit 5e55618
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions packages/js-dash-sdk/karma/options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const dotenvResult = require('dotenv').config();
const dotenvSafe = require('dotenv-safe');

const karmaMocha = require('karma-mocha');
const karmaMochaReporter = require('karma-mocha-reporter');
Expand All @@ -9,6 +9,15 @@ const karmaChromeLauncher = require('karma-chrome-launcher');
const karmaWebpack = require('karma-webpack');
const webpackBaseConfig = require('../webpack.base.config');

let env = {};
if (process.env.LOAD_ENV) {
const dotenvResult = dotenvSafe.config();
if (dotenvResult.error) {
throw dotenvResult.error;
}
env = dotenvResult.parsed;
}

module.exports = {
frameworks: ['mocha', 'chai', 'webpack'],
webpack: {
Expand All @@ -17,7 +26,7 @@ module.exports = {
plugins: [
...webpackBaseConfig.plugins,
new webpack.EnvironmentPlugin(
dotenvResult.parsed,
env,
),
],
},
Expand Down
6 changes: 3 additions & 3 deletions packages/js-dash-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"lint:fix": "eslint . --fix",
"test": "yarn run test:types && yarn run test:unit && yarn run test:browsers",
"test:browsers": "karma start ./karma/karma.conf.js --single-run",
"test:browsers:functional": "karma start ./karma/karma.functional.conf.js --single-run",
"test:browsers:functional": "LOAD_ENV=true karma start ./karma/karma.functional.conf.js --single-run",
"test:unit": "ts-mocha -p tsconfig.mocha.json src/**/*.spec.ts",
"test:functional": "yarn run build && mocha --recursive tests/functional/**/*.js",
"test:functional": "yarn run build:ts && LOAD_ENV=true mocha --recursive tests/functional/**/*.js",
"test:types": "yarn pnpify tsd",
"prepublishOnly": "yarn run build",
"prepare": "yarn run build"
Expand Down Expand Up @@ -72,7 +72,7 @@
"chance": "^1.1.6",
"crypto-browserify": "^3.12.0",
"dirty-chai": "^2.0.1",
"dotenv": "^8.6.0",
"dotenv-safe": "^8.2.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^17.0.0",
Expand Down
11 changes: 6 additions & 5 deletions packages/js-dash-sdk/src/test/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const dotenv = require('dotenv');
const path = require('path');

const dotenvSafe = require('dotenv-safe');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
const { use } = require('chai');
const dirtyChai = require('dirty-chai');
const chaiAsPromised = require('chai-as-promised');

dotenv.config({
path: path.resolve(__dirname, '..', '..', '.env'),
});
if (process.env.LOAD_ENV === 'true') {
dotenvSafe.config({
path: path.resolve(__dirname, '..', '..', '.env'),
});
}

use(dirtyChai);
use(sinonChai);
Expand Down
13 changes: 11 additions & 2 deletions packages/wallet-lib/karma/options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
const dotenvResult = require('dotenv').config();
const dotenvSafe = require('dotenv-safe');

const karmaMocha = require('karma-mocha');
const karmaMochaReporter = require('karma-mocha-reporter');
Expand All @@ -11,6 +11,15 @@ const karmaWebpack = require('karma-webpack');

const webpackConfig = require('../webpack.config');

let env = {};
if (process.env.LOAD_ENV) {
const dotenvResult = dotenvSafe.config();
if (dotenvResult.error) {
throw dotenvResult.error;
}
env = dotenvResult.parsed;
}

module.exports = {
client: {
mocha: {
Expand All @@ -24,7 +33,7 @@ module.exports = {
plugins: [
...webpackConfig.plugins,
new webpack.EnvironmentPlugin(
dotenvResult.parsed,
env,
),
],
resolve: webpackConfig.resolve,
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test:unit": "nyc yarn mocha 'src/**/*.spec.js'",
"test:functional": "nyc yarn run mocha 'tests/functional/*.js'",
"test:functional": "LOAD_ENV=true nyc yarn run mocha 'tests/functional/*.js'",
"test:integration": "nyc yarn run mocha 'tests/integration/**/*.spec.js'",
"test:browsers": "karma start ./karma/karma.conf.js --single-run",
"test:browsers:functional": "karma start ./karma/karma.functional.conf.js --single-run",
"test:browsers:functional": "LOAD_ENV=true karma start ./karma/karma.functional.conf.js --single-run",
"test:types": "yarn pnpify tsd",
"test": "yarn run test:types && yarn run test:unit && yarn run test:integration && yarn run test:browsers",
"prepublishOnly": "yarn run build:web"
Expand Down Expand Up @@ -66,7 +66,7 @@
"chai-as-promised": "^7.1.1",
"crypto-browserify": "^3.12.0",
"dirty-chai": "^2.0.1",
"dotenv": "^8.6.0",
"dotenv-safe": "^8.2.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.24.2",
Expand Down
10 changes: 6 additions & 4 deletions packages/wallet-lib/src/test/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { use } = require('chai');
const { expect } = require('chai');
const dotenvSafe = require('dotenv-safe');
const path = require('path');
const dotenv = require('dotenv');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
const dirtyChai = require('dirty-chai');
Expand All @@ -11,9 +11,11 @@ use(sinonChai);
use(dirtyChai);
use(chaiAsPromised);

dotenv.config({
path: path.resolve(__dirname, '..', '..', '.env'),
});
if (process.env.LOAD_ENV === 'true') {
dotenvSafe.config({
path: path.resolve(__dirname, '..', '..', '.env'),
});
}

beforeEach(function beforeEach() {
if (!this.sinon) {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,7 @@ __metadata:
crypto-browserify: ^3.12.0
crypto-js: ^4.0.0
dirty-chai: ^2.0.1
dotenv: ^8.6.0
dotenv-safe: ^8.2.0
eslint: ^7.32.0
eslint-config-airbnb-base: ^14.2.1
eslint-plugin-import: ^2.24.2
Expand Down Expand Up @@ -6117,7 +6117,7 @@ __metadata:
chance: ^1.1.6
crypto-browserify: ^3.12.0
dirty-chai: ^2.0.1
dotenv: ^8.6.0
dotenv-safe: ^8.2.0
eslint: ^7.32.0
eslint-config-airbnb-base: ^14.2.1
eslint-config-airbnb-typescript: ^17.0.0
Expand Down

0 comments on commit 5e55618

Please sign in to comment.