Skip to content

Commit

Permalink
increase test coverage (#206)
Browse files Browse the repository at this point in the history
* add instrumentor

* add changes to increase code coverage

* fix broken tests and cleanup unused code

* Update yarn.lock

* Add source-map-loader
  • Loading branch information
chuckcarpenter authored and RobbieTheWagner committed Aug 13, 2018
1 parent 0079f56 commit 2a7a3a1
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ module.exports = {
}
}
]
};
};
52 changes: 42 additions & 10 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,58 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
'dist/js/*.js',
'test/*.js'
'src/js/*.js',
'test/test.*.js'
],

// list of files / patterns to exclude
exclude: [
],

coverageIstanbulReporter: {
dir: '../coverage',
fixWebpackSourcePaths: true,
reports: ['cobertura', 'lcov', 'html', 'text', 'text-summary'],
skipFilesWithNoCoverage: true
},

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'src/js/*.js': ['webpack', 'coverage'],
'test/test.*.js': ['webpack']
'src/js/*.js': ['webpack', 'sourcemap', 'coverage'],
'test/test.*.js': ['webpack', 'sourcemap']
},

coverageReporter: {
dir: 'coverage/',
reporters: [
{ type: 'lcov', subdir: '.' }
]
webpack: {
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader',
exclude: [
'node_modules'
]
},
{
test: /\.js$/,
exclude: [
/node_modules/,
/test/
],
use: [
{ loader: 'istanbul-instrumenter-loader', options: { esModules: true } },
'babel-loader'
]
},
{
test: /test.*\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
}
]
},
devtool: 'inline-source-map'
},

// web server port
Expand Down Expand Up @@ -65,7 +97,7 @@ module.exports = function(config) {
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha', 'coverage'],
reporters: ['coverage-istanbul', 'mocha'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,23 @@
"eslint-plugin-mocha": "^5.1.0",
"eslint-plugin-ship-shape": "^0.6.0",
"glob": "^7.1.2",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^2.0.5",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-coverage-istanbul-reporter": "^2.0.1",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.0",
"mini-css-extract-plugin": "^0.4.1",
"mocha": "^5.2.0",
"node-sass": "^4.9.2",
"postcss": "^7.0.2",
"postcss-loader": "^2.1.6",
"sass-loader": "^7.1.0",
"source-map-loader": "^0.2.3",
"style-loader": "^0.21.0",
"stylelint": "^9.3.0",
"stylelint-config-ship-shape": "^0.4.0",
Expand Down
4 changes: 3 additions & 1 deletion test/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module.exports = {
'plugin:mocha/recommended'
],
globals: {
document: true,
window: true,
assert: false,
Shepherd: false
},
Expand All @@ -23,4 +25,4 @@ module.exports = {
rules: {
'no-console': 'off'
}
};
};
54 changes: 54 additions & 0 deletions test/test.step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* global describe,it */
import assert from 'assert';
import Shepherd from '../src/js/shepherd.js';
// since importing non UMD, needs assignment
window.Shepherd = Shepherd;

describe('Shepherd', function() {
describe('.Step()', function() {
const instance = new Shepherd.Tour({
defaults: {
classes: 'shepherd-theme-arrows',
scrollTo: true
}
});

const testStep = instance.addStep('test', {
id: 'test',
text: 'This is a step for testing',
classes: 'example-step-extra-class',
buttons: [
{
text: 'Next',
action: instance.next
}
]
});
const showTestStep = instance.addStep('test2', {
id: 'test2',
text: 'Another Step'
});

it('has all the correct properties', function() {
const values = ['classes', 'scrollTo', 'id', 'text', 'buttons'];
assert.deepEqual(values, Object.keys(testStep.options));
});

describe('.hide()', function() {
it('shows step evoking method, regardless of order', function() {
instance.start();
testStep.hide();

assert.notEqual(document.querySelector('[data-id=test]').getAttribute('hidden'), null);
});
});
describe('.show()', function() {
it('shows step evoking method, regardless of order', function() {
showTestStep.show();

assert.equal(document.querySelector('[data-id=test2]').dataset.id, 'test2');
});
});

});
});
62 changes: 51 additions & 11 deletions test/test.tour.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
/* global require,describe,it */
const assert = require('assert');
const Shepherd = require('../dist/js/shepherd.js');
/* global window,require,describe,it */
import assert from 'assert';
import Shepherd from '../src/js/shepherd.js';
// since importing non UMD, needs assignment
window.Shepherd = Shepherd;

describe('Shepherd', function() {
const defaults = {
classes: 'shepherd-theme-arrows',
scrollTo: true
};
describe('.Tour()', function() {
after(function() {
instance.cancel();
});
const instance = new Shepherd.Tour({
defaults: {
classes: 'shepherd-theme-arrows',
scrollTo: true
}
defaults,
});
it('creates a new tour instance', function() {
assert.ok(instance instanceof Shepherd.Tour);
Expand All @@ -21,25 +27,59 @@ describe('Shepherd', function() {
describe('.addStep()', function() {
it('adds tour steps', function() {
instance.addStep('test', {
text: 'This is a test step for our tour'
id: 'test',
title: 'This is a test step for our tour'
});

assert.equal(instance.steps.length, 1);
});

// this is not working as documented
it.skip('returns the step options', function() {
assert.ok(instance.defaults);
it('returns the step options', function() {
assert.equal(instance.options.defaults, defaults);
});

it('returns the step by ID with the right title', function() {
instance.addStep('test2', {
id: 'test2',
title: 'Another Step'
});

instance.addStep('test3', {
id: 'test3',
title: 'Yet, another test step'
});
assert.equal(instance.steps.length, 3);
assert.equal(instance.getById('test').options.title, 'This is a test step for our tour');
});

});

describe.skip('.start()', function() {
describe('.start()', function() {
it('starts a tour that is the current active', function() {
instance.start();

assert.equal(instance, Shepherd.activeTour);
});
});

describe('.getCurrentStep()', function() {
it('returns the currently shown step', function() {
assert.equal(instance.getCurrentStep().id, 'test');
});
});
describe('.next()', function() {
it('goes to the next step after next() is evoked', function() {
instance.next();
assert.equal(instance.getCurrentStep().id, 'test2');
});
});
describe('.back()', function() {
it('goes to the previous step after back() is evoked', function() {
instance.back();
assert.equal(instance.getCurrentStep().id, 'test');
});
});

});
});
Loading

0 comments on commit 2a7a3a1

Please sign in to comment.