Skip to content

Commit

Permalink
Merge coverage from cypress and unit tests (#225)
Browse files Browse the repository at this point in the history
* Merge coverage from cypress and unit tests

* Use start-server-and-test

* Use mocha-headless-chrome instead of karma

* Remove karma.conf.js
  • Loading branch information
RobbieTheWagner authored Aug 27, 2018
1 parent d426b49 commit d5c4740
Show file tree
Hide file tree
Showing 25 changed files with 571 additions and 637 deletions.
7 changes: 6 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"plugins": [
"add-module-exports",
"lodash"
]
],
"env": {
"test": {
"plugins": [ "istanbul" ]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/cypress/
/dist/
/node_modules/
/test/unit/dist
/.DS_Store
/.sass-cache
/npm-debug.log*
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
include:
- stage: test
script:
- yarn build
- yarn test:ci
after_script:
- codeclimate-test-reporter < coverage/lcov.info
Expand Down
7 changes: 5 additions & 2 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"fixturesFolder": "test/fixtures",
"integrationFolder": "test/integration",
"coverageFolder": "coverage",
"fixturesFolder": "test/cypress/fixtures",
"integrationFolder": "test/cypress/integration",
"pluginsFile": "test/cypress/plugins/index.js",
"supportFile": "test/cypress/support/index.js",
"video": false
}
113 changes: 0 additions & 113 deletions karma.conf.js

This file was deleted.

30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
"postbuild": "rm -f dist/removable-*",
"clean": "rm -rf dist",
"cy:open": "./node_modules/.bin/cypress open",
"cy:run": "./node_modules/.bin/cypress run",
"cy:run": "./node_modules/.bin/cypress run --env coverage=true",
"mocha-headless-chrome": "mocha-headless-chrome -c coverage/coverage.json -f test/unit/index.html -a no-sandbox",
"posttest:ci": "nyc report --reporter=lcov --reporter=text",
"start": "yarn watch",
"start-test-server": "http-server",
"test:build": "cross-env NODE_ENV=test yarn build",
"test:ci": "yarn test:unit:ci && yarn test:cy:ci",
"test:cy:ci": "start-server-and-test start-test-server http://localhost:8080 cy:run",
"test:cy:ci": "yarn test:build && start-server-and-test start-test-server http://localhost:8080 cy:run",
"test:cy:watch": "start-server-and-test start-test-server http://localhost:8080 cy:open",
"test:unit:ci": "karma start --single-run --browsers ChromeHeadlessNoSandbox",
"test:unit:watch": "karma start --browsers Chrome",
"test": "mocha",
"test:unit:ci": "cross-env NODE_ENV=test webpack --config webpack.test.config.js && yarn mocha-headless-chrome",
"watch": "yarn clean && webpack --watch --mode development"
},
"homepage": "http://shipshapecode.github.io/shepherd/docs/welcome/",
Expand All @@ -45,16 +46,18 @@
},
"devDependencies": {
"autoprefixer": "^9.1.3",
"babel-core": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-istanbul": "^4.1.6",
"babel-plugin-lodash": "^3.3.4",
"babel-preset-env": "^1.6.1",
"browser-sync": "^2.24.6",
"browser-sync-webpack-plugin": "^2.2.2",
"chai": "^4.1.2",
"codeclimate-test-reporter": "^0.5.0",
"copy-webpack-plugin": "^4.5.2",
"cross-env": "^5.2.0",
"css-loader": "^1.0.0",
"cypress": "^3.0.3",
"del": "^3.0.0",
Expand All @@ -68,17 +71,12 @@
"http-server": "^0.11.1",
"inject-loader": "^4.0.1",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^3.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-coverage-istanbul-reporter": "^2.0.2",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.0",
"istanbul-lib-coverage": "^1.2.0",
"lodash-webpack-plugin": "^0.11.5",
"mocha": "^5.2.0",
"mocha-headless-chrome": "^2.0.1",
"node-sass": "^4.9.2",
"nyc": "^12.0.2",
"postcss": "^7.0.2",
"postcss-loader": "^3.0.0",
"sass-loader": "^7.1.0",
Expand All @@ -94,5 +92,9 @@
},
"engines": {
"node": ">= 6.*"
},
"nyc": {
"temp-directory": "./coverage",
"report-dir": "./coverage"
}
}
2 changes: 1 addition & 1 deletion src/js/bind.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseShorthand } from './utils';
import { parseShorthand } from './utils.js';
import _ from 'lodash';

/**
Expand Down
6 changes: 3 additions & 3 deletions src/js/shepherd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Evented } from './evented';
import { Step } from './step';
import { Shepherd, Tour } from './tour';
import { Evented } from './evented.js';
import { Step } from './step.js';
import { Shepherd, Tour } from './tour.js';

Object.assign(Shepherd, { Tour, Step, Evented });

Expand Down
6 changes: 3 additions & 3 deletions src/js/step.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import _ from 'lodash';
import { Evented } from './evented';
import { Evented } from './evented.js';
import 'element-matches';
import { bindAdvance, bindButtonEvents, bindCancelLink, bindMethods } from './bind';
import { createFromHTML, parsePosition, setupPopper } from './utils';
import { bindAdvance, bindButtonEvents, bindCancelLink, bindMethods } from './bind.js';
import { createFromHTML, parsePosition, setupPopper } from './utils.js';

/**
* Creates incremented ID for each newly created step
Expand Down
6 changes: 3 additions & 3 deletions src/js/tour.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import { Evented } from './evented';
import { Step } from './step';
import { bindMethods } from './bind';
import { Evented } from './evented.js';
import { Step } from './step.js';
import { bindMethods } from './bind.js';

const Shepherd = new Evented();

Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions test/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

let coverageMap;

module.exports = (on, config) => {
if(config.env.coverage) {
const istanbul = require('istanbul-lib-coverage');
coverageMap = istanbul.createCoverageMap({});

on('task', {
'coverage'(coverage) {
coverageMap.merge(coverage);
return JSON.stringify(coverageMap);
}
});
}

return config;
};
31 changes: 31 additions & 0 deletions test/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//

if(Cypress.env('coverage')) {
afterEach(function() {
const coverageFile = `${ Cypress.config('coverageFolder') }/out.json`;

cy.window().then(win => {
const coverage = win.__coverage__;

if(!coverage) return;

cy.task('coverage', coverage).then(map => {
cy.writeFile(coverageFile, map);

if(Cypress.env('coverage') === 'open') {
cy.exec('nyc report --reporter=html');
}
});
});
});
}
20 changes: 20 additions & 0 deletions test/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions test/unit/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link href="../../node_modules/mocha/mocha.css" rel="stylesheet"/>
<script src="../../node_modules/mocha/mocha.js"></script>
</head>
<body>
<div id="mocha"></div>
<script src="dist/bundle.js"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions test/unit/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import './test.evented.js';
import './test.step.js';
import './test.tour.js';
import './test.utils.js';

mocha.checkLeaks();
mocha.run();
1 change: 1 addition & 0 deletions test/unit/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mocha.setup('bdd');
2 changes: 1 addition & 1 deletion test/test.evented.js → test/unit/test.evented.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert } from 'chai';
import { Evented } from '../src/js/evented';
import { Evented } from '../../src/js/evented.js';

describe('Evented', () => {
let testEvent, testOnTriggered;
Expand Down
4 changes: 2 additions & 2 deletions test/test.step.js → test/unit/test.step.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert } from 'chai';
import Shepherd from '../src/js/shepherd';
import { Step } from '../src/js/step';
import Shepherd from '../../src/js/shepherd.js';
import { Step } from '../../src/js/step.js';
// since importing non UMD, needs assignment
window.Shepherd = Shepherd;

Expand Down
Loading

0 comments on commit d5c4740

Please sign in to comment.