Skip to content

Commit

Permalink
use babel for instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Aug 26, 2021
1 parent 7cd8e47 commit 1dfc6b3
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 1,952 deletions.
7 changes: 6 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
"modules": false
}
]
]
],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
}
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"quote-props": "off",
"react/jsx-filename-extension": "off",
"no-script-url": "off",
"jsx-a11y/anchor-is-valid": "off"
"jsx-a11y/anchor-is-valid": "off",
"import/no-extraneous-dependencies": "off"
}
}
6 changes: 4 additions & 2 deletions grunt/aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ setup:
- copy:discovery_vars

test:prod:
- env:test
- clean:temp
- clean:coverage
- clean:release
- copy:release
- babel
- babel:temp
- babel:release
- string-replace:final
- exec:nyc-instrument
- babel:instrument
- server:once
- puppet:prod
- coverage-report:coveralls
Expand Down
10 changes: 10 additions & 0 deletions grunt/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ module.exports = {
},
],
},
instrument: {
files: [
{
expand: true,
cwd: 'dist/js',
src: '**/*.js',
dest: 'test/coverage/instrument',
},
],
},
temp: {
files: [
{
Expand Down
63 changes: 39 additions & 24 deletions grunt/coverage-report.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
'use strict';
/* eslint-disable global-require */
/**
* creating coverage task
*
* @module grunt/coverage
*/
module.exports = function (grunt) {
module.exports = function(grunt) {
const COVERAGE_HTML_OUTPUT_DIR = 'test/coverage/reports/html';
const COVERAGE_LCOV_OUTPUT_DIR = 'test/coverage/reports/lcov';
const COVERAGE_COLLECTION_FILE = 'test/coverage/coverage.json';

var istanbul = require('istanbul');
var COVERAGE_HTML_OUTPUT_DIR = 'test/coverage/reports/html';
var COVERAGE_LCOV_OUTPUT_DIR = 'test/coverage/reports/lcov';
var COVERAGE_COLLECTION_FILE = 'test/coverage/coverage.json';
grunt.registerMultiTask('coverage-report', function() {
const istanbul = require('istanbul');
const options = this.options({ htmlReport: false });

grunt.registerMultiTask('coverage-report', function () {
// get the coverage object from the collection file generated
const coverageObject = grunt.file.readJSON(COVERAGE_COLLECTION_FILE);

var options = this.options({ htmlReport: false });
/**
* For some reason, possible configuration? -- the instrumentor adds a base prefix to the paths
* this breaks when we try to run through them, so this will remove that base from all the coverage paths
*/
const normalizedCoverageObject = Object.keys(coverageObject).reduce(
(acc, k) => {
const newPath = k.replace(/^dist\/js\//g, '');

// get the coverage object from the collection file generated
var coverageObject = grunt.file.readJSON(COVERAGE_COLLECTION_FILE);
var collector = new istanbul.Collector();
collector.add(coverageObject);
return {
...acc,
[newPath]: {
...coverageObject[k],
path: newPath,
},
};
},
{}
);
const collector = new istanbul.Collector();
collector.add(normalizedCoverageObject);

// Generate a quick summary to be shown in the output
var finalCoverage = collector.getFinalCoverage();
var summary = istanbul.utils.summarizeCoverage(finalCoverage);
const finalCoverage = collector.getFinalCoverage();
const summary = istanbul.utils.summarizeCoverage(finalCoverage);

// Output the percentages of the coverage
grunt.log.ok('Coverage:');
Expand All @@ -34,23 +51,21 @@ module.exports = function (grunt) {
// write reports
if (options.htmlReport) {
istanbul.Report.create('html', {
dir: COVERAGE_HTML_OUTPUT_DIR
dir: COVERAGE_HTML_OUTPUT_DIR,
}).writeReport(collector, true);
}

istanbul.Report.create('lcov', {
dir: COVERAGE_LCOV_OUTPUT_DIR
dir: COVERAGE_LCOV_OUTPUT_DIR,
}).writeReport(collector, true);
});

return {
'coveralls': {
htmlReport: false
coveralls: {
htmlReport: false,
},
'html': {
htmlReport: true
}
}
html: {
htmlReport: true,
},
};
};


13 changes: 8 additions & 5 deletions grunt/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ module.exports = {
dev: {
NODE_ENV: 'development',
SERVER_ENV: 'dev',
TARGET: 'dev'
TARGET: 'dev',
},
prod: {
NODE_ENV: 'production',
SERVER_ENV: 'dev',
TARGET: 'prod'
TARGET: 'prod',
},
test: {
NODE_ENV: 'test',
},
'release-prod': {
NODE_ENV: 'production',
SERVER_ENV: 'release',
TARGET: 'prod'
TARGET: 'prod',
},
'release-dev': {
NODE_ENV: 'development',
SERVER_ENV: 'release',
TARGET: 'dev'
}
TARGET: 'dev',
},
};

0 comments on commit 1dfc6b3

Please sign in to comment.