Skip to content

Commit

Permalink
Rewrite tests
Browse files Browse the repository at this point in the history
Rewrite lab tests in avajs due to lab not supporting ESM currently.
Add dependency injection for presenter to increase testability.
  • Loading branch information
binarymist committed Feb 7, 2022
1 parent 4a3a1f1 commit b541e11
Show file tree
Hide file tree
Showing 17 changed files with 6,271 additions and 3,443 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module.exports = {
// enforce consistent line breaks inside function parentheses
// https://eslint.org/docs/rules/function-paren-newline
'function-paren-newline': ['error', 'multiline'],
'import/no-unresolved': ['error', { ignore: ['purpleteam-logger', 'chalk', 'got'] }],
// Eslint can't deal with ESM modules currently.
'import/no-unresolved': ['error', { ignore: ['ava', 'chalk', 'got', 'purpleteam-logger'] }],
// Used in order to supress the errors in the use of appending file extensions to the import statement for local modules
// Which is required in order to upgrade from CJS to ESM. At time of upgrade file extensions have to be provided in import statements.
'import/extensions': ['error', { 'js': 'ignorePackages' }],
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ node_modules/
config.*.json
!config.example.local.json
!config.example.cloud.json
!config.test.json
!config.localtest.json

.vscode
*.code-workspace
Expand Down
22 changes: 14 additions & 8 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ convict.addFormats(convictFormatWithValidator);
const schema = {
env: {
doc: 'The application environment.',
format: ['cloud', 'local', 'test'],
format: ['cloud', 'local', 'cloudtest', 'localtest'],
default: 'cloud',
env: 'NODE_ENV'
},
Expand Down Expand Up @@ -193,7 +193,7 @@ const schema = {
dir: {
doc: 'The location of the results.',
format: String,
default: `${process.cwd()}/outcomes/`
default: path.join(process.cwd(), '/outcomes/')
},
fileName: {
doc: 'The name of the archive file containing all of the Tester outcomes (results, reports).',
Expand Down Expand Up @@ -226,10 +226,16 @@ const schema = {
}
},
uI: {
doc: 'The user interface used. cUi is usually the best option for running the purpleteam CLI standalone, noUi is usually the best option for running the purpleteam CLI from within another process',
format: ['cUi', 'noUi'],
default: 'cUi',
env: 'PURPLETEAM_UI'
type: {
doc: 'The user interface used. cUi is usually the best option for running the purpleteam CLI standalone, noUi is usually the best option for running the purpleteam CLI from within another process',
format: ['cUi', 'noUi'],
default: 'cUi',
env: 'PURPLETEAM_UI'
},
path: {
cUi: path.join(process.cwd(), '/src/view/cUi.js'),
noUi: path.join(process.cwd(), '/src/view/noUi.js')
}
}
};

Expand All @@ -239,8 +245,8 @@ const config = convict(schema);
// Doc: https://github.com/mozilla/node-convict/tree/master/packages/convict#configloadfilefile-or-filearray
// config.loadFile([path.join(__dirname, `config.${process.env.NODE_ENV}.json`), '/my/locked/down/purpleteam_secrets.json']);
const filename = fileURLToPath(import.meta.url);
const directoryName = dirname(filename);
config.loadFile(path.join(directoryName, `config.${process.env.NODE_ENV}.json`));
const currentDirName = dirname(filename);
config.loadFile(path.join(currentDirName, `config.${process.env.NODE_ENV}.json`));
config.validate();

config.set('purpleteamApi.url', `${config.get('purpleteamApi.protocol')}://${config.get('purpleteamApi.host')}:${config.get('purpleteamApi.port')}`);
Expand Down
File renamed without changes.
Loading

0 comments on commit b541e11

Please sign in to comment.