Skip to content

Commit

Permalink
Chore: (tests) moves load to factory
Browse files Browse the repository at this point in the history
  • Loading branch information
pustovitDmytro committed May 8, 2021
1 parent 4ffb878 commit 4acb941
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .mocharc.bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"color": true,
"full-trace": true,
"recursive": true,
"require": ["./tests/test.env.js"]
"require": ["./tests/init.js"]
}
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"color": true,
"full-trace": true,
"recursive": true,
"require": ["./tests/test.env.js", "@babel/register"]
"require": ["./tests/init.js", "@babel/register"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"danger": "^10.6.4",
"eslint": "^7.0.0",
"eslint-config-incredible": "^1.9.0",
"eslint-plugin-censor": "^1.3.0",
"eslint-plugin-censor": "^1.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-security": "^1.4.0",
"fs-extra": "^10.0.0",
Expand Down
17 changes: 15 additions & 2 deletions tests/Test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import fse from 'fs-extra';
import { tmpFolder } from './constants';
import { tmpFolder, entry } from './constants';

export default class Test {
async setTmpFolder() {
Expand All @@ -11,6 +12,18 @@ export default class Test {
}
}

function load(relPath) {
// eslint-disable-next-line security/detect-non-literal-require
return require(path.join(entry, relPath));
}

function resolve(relPath) {
return require.resolve(path.join(entry, relPath));
}

export {
tmpFolder
tmpFolder,
entry,
load,
resolve
};
8 changes: 7 additions & 1 deletion tests/constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import path from 'path';

const isBuild = process.env.BUILD && [ '1', 'true' ].includes(process.env.BUILD);
const entry = process.env.ENTRY && path.resolve(process.env.ENTRY)
|| isBuild && path.resolve(__dirname, '../lib')
|| path.resolve(__dirname, '../src');

const tmpFolder = path.join(__dirname, '../tmp/tests');

export {
tmpFolder
tmpFolder,
entry
};
16 changes: 1 addition & 15 deletions tests/entry.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
/* eslint-disable security/detect-non-literal-require */
import path from 'path';

const isBuild = process.env.BUILD && [ '1', 'true' ].includes(process.env.BUILD);
const entry = process.env.ENTRY && path.resolve(process.env.ENTRY)
|| isBuild && path.resolve(__dirname, '../lib')
|| path.resolve(__dirname, '../src');
import { entry } from './constants';

export default require(entry);
module.exports = require(entry);
function _load(relPath) {
return require(path.join(entry, relPath));
}

_load.resolve = function (relPath) {
return require.resolve(path.join(entry, relPath));
};

export { _load };
Empty file added tests/init.js
Empty file.
1 change: 0 additions & 1 deletion tests/test.env.js

This file was deleted.

0 comments on commit 4acb941

Please sign in to comment.