Skip to content

Instantly share code, notes, and snippets.

@plroebuck
Last active March 10, 2019 13:54
Show Gist options
  • Save plroebuck/7900f3a3ff3949c3c208b3250b34894b to your computer and use it in GitHub Desktop.
Save plroebuck/7900f3a3ff3949c3c208b3250b34894b to your computer and use it in GitHub Desktop.
Custom Location is not working as expected for `mocha --config`

Issue: Custom Location is not working as expected for --config

PREREQUISITE: Instructions assume installation of Allure Framework completed and functioning.

Create parent folder

$ cd /var/tmp
$ mkdir git_test
$ cd git_test

Create "ace-api-testlib" package

$ mkdir ace-api-testlib
$ cd ace-api-testlib
$ cat << EOF >> "package.json"
{
  "name": "ace-api-testlib",
  "version": "1.0.7",
  "description": "Provides something...",
  "main": "index.js",
  "dependencies": {
    "mkdirp": "^0.5.1",
    "rimraf": "^2.6.3"
  },
  "devDependencies": {
    "allure-commandline": "^2.9.0",
    "mocha": "^6.0.2",
    "mocha-allure-reporter": "^1.4.0"
  },
  "files": [
    "lib",
    "test"
  ],
  "directories": {
    "build": "target",
    "lib": "lib",
    "test": "test"
  },
  "allure": {
    "results": "$npm_package_directories_build/allure-results",
    "report": "$npm_package_directories_build/allure-report"
  },
  "scripts": {
    "allure:generate": "allure generate $npm_package_allure_results --clean -o $npm_package_allure_report",
    "allure:open": "allure open $npm_package_allure_report",
    "clean": "rimraf $npm_package_directories_build",
    "mkdir:build": "mkdirp $npm_package_directories_build",
    "pretest": "npm run clean && npm run mkdir:build",
    "report": "npm run allure:generate && npm run allure:open",
    "test": "OUTDIR=$npm_package_directories_build mocha"
  },
  "repository": {
    "type": "git",
    "url": "https://stash.intralinks.com/scm/ace/ace-api-testlib.git"
  },
  "author": "ace-api",
  "license": "ISC"
}
EOF
$ mkdir lib test
$ touch index.js
$ cat << EOF >> ".mocharc.js"
'use strict';

const path = require('path');

const FIFTY_SECS = 50000;
const DEFAULT_BUILD_DIR = 'target';
const HOOKS_FILE = 'mocha.global.js';

const buildDir = process.env.OUTDIR
  ? process.env.OUTDIR
  : DEFAULT_BUILD_DIR;

const allureArtifactsDir = path.join(buildDir, 'allure-results');
const hooksFile = require.resolve(
  path.join('./test', HOOKS_FILE)
);

module.exports = {
  timeout: FIFTY_SECS,
  file: hooksFile,
  opts: false,
  reporter: 'mocha-allure-reporter',
  reporterOption: [ 'targetDir=' + allureArtifactsDir ]
};
EOF
$ cat << EOF >> "test/mocha.global.js"
console.log('loading global hooks and such...');
EOF
$ cat << EOF >> "test/e2e.spec.js"
'use strict';

var assert = require('assert');

describe('e2e tests for ace-ilp-lib', () => {
  console.log('running e2e tests');
  it('should be able to execute an integration test', () => {
    assert.ok(true);
  });
});
EOF
$ npm install
$ cd ..

Create "ace-ilp-lib" package

$ mkdir ace-ilp-lib
$ cd ace-ilp-lib
$ cat << EOF >> "package.json"
{
  "name": "ace-ilp-lib",
  "version": "1.0.9",
  "description": "Provides basic test framework support, including session management, logging, test data management",
  "main": "index.js",
  "dependencies": {
    "ace-api-testlib": "file:../ace-api-testlib",
    "mkdirp": "^0.5.1",
    "rimraf": "^2.6.3"
  },
  "devDependencies": {
    "allure-commandline": "^2.9.0",
    "mocha": "^6.0.2",
    "mocha-allure-reporter": "^1.4.0"
  },
  "files": [
    "lib",
    "test"
  ],
  "directories": {
    "build": "target",
    "lib": "lib",
    "test": "test"
  },
  "allure": {
    "results": "$npm_package_directories_build/allure-results",
    "report": "$npm_package_directories_build/allure-report"
  },
  "scripts": {
    "allure:generate": "allure generate $npm_package_allure_results --clean -o $npm_package_allure_report",
    "allure:open": "allure open $npm_package_allure_report",
    "clean": "rimraf $npm_package_directories_build",
    "mkdir:build": "mkdirp $npm_package_directories_build",
    "pretest": "npm run clean && npm run mkdir:build",
    "report": "npm run allure:generate && npm run allure:open",
    "test": "OUTDIR=$npm_package_directories_build mocha --config ace-api-testlib/.mocharc.js"
  },
  "repository": {
    "type": "git",
    "url": "https://stash.intralinks.com/scm/ace/ace-ilp-lib.git"
  },
  "author": "ace-api",
  "license": "ISC"
}
EOF
$ mkdir lib test
$ touch index.js
$ cat << EOF >> "test/unit.spec.js"
'use strict';

var assert = require('assert');

describe('unit tests for ace-ilp-lib', () => {
  console.log('running unit tests');
  it('should be able to execute a unit test', () => {
    assert.ok(true);
  });
});
EOF
$ npm install
$ cd ..

Run tests

$ (cd ace-ilp-lib; npm test && npm run report)
$ (cd ace-api-testlib; npm test && npm run report)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment