Skip to content

Commit

Permalink
Tests fixes (rubenspgcavalcante#57)
Browse files Browse the repository at this point in the history
* Fixed webpack loader config on Karma

* fixed tests

* removed istanbul coverage

* raising travis node version to 8
  • Loading branch information
rubenspgcavalcante authored Apr 29, 2018
1 parent 6c99f7b commit 00dc278
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 20 deletions.
13 changes: 8 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
"add-module-exports",
"transform-class-properties",
"transform-object-rest-spread",
["transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": true
}]
[
"transform-runtime",
{
"helpers": false,
"polyfill": false,
"regenerator": true
}
]
]
}
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
language: node_js
node_js:
- '7'
- '8'

before_script: npm run build
before_script: yarn build
script: yarn test
after_success: yarn codacy

cache: yarn
branches:
Expand Down
24 changes: 18 additions & 6 deletions karma/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const {resolve} = require("path");
const webpackLoaders = require("./../webpack/loaders.js");

module.exports = function (config) {
Expand All @@ -9,33 +10,44 @@ module.exports = function (config) {
"karma-webpack",
"karma-babel-preprocessor",
"karma-phantomjs-launcher",
"karma-chrome-launcher",
"karma-jasmine",
"karma-sourcemap-loader",
"karma-sourcemap-writer",
"karma-coverage",
"karma-remap-istanbul"
],

reporters: ["progress", "coverage", "karma-remap-istanbul"],
/**
* FIXME: Removed karma-remap-istanbul because of istanbul error
* @see https://github.com/gotwarlost/istanbul/issues/602
*/
reporters: ["progress", "coverage"],

preprocessors: {
"./webpack.tests.js": ["webpack", "sourcemap", "sourcemap-writer", "coverage"]
},

webpack: {
mode: "development",
entry: ["./webpack.tests.js"],
devtool: "inline-source-map",
output: {
path: "dist/",
filename: "tests.js"
},
module: {
loaders: webpackLoaders.concat([
rules: webpackLoaders.concat([
{
enforce: "pre",
enforce: "post",
test: /\.js$/,
include: "./src/",
loader: "istanbul-instrumenter"
include: resolve(__dirname, "../src/"),
use: {
loader: "istanbul-instrumenter-loader",
options: {
esModules: true
}
}
}
])
}
Expand All @@ -56,7 +68,7 @@ module.exports = function (config) {
},

files: [
"node_modules/babel-polyfill/dist/polyfill.min.js",
require.resolve("babel-polyfill/dist/polyfill.min.js"),
"./webpack.tests.js",
],

Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
"main": "dist/leaflet-ant-path.js",
"scripts": {
"build": "NODE_ENV=production webpack --colors --profile --progress",
"test": "karma start karma/karma.conf.js --log-level debug --single-run && node karma/clean-report.js",
"test": "NODE_ENV=test karma start karma/karma.conf.js --single-run",
"test:chrome": "npm run test -- --browsers=Chrome --single-run=false",
"clean-report": "node karma/clean-report.js",
"analyze": "NODE_ENV=production webpack --profile --json > .wbprofile.json && webpack-bundle-analyzer .wbprofile.json -m server",
"format": "prettier-eslint --write \"{dev-env,src}/**/*.js\"",
"start": "NODE_ENV=development webpack-dev-server -d --cache --inline --host 0.0.0.0",
"codacy": "cat coverage/lcov.info | codacy-coverage",
"prepublish": "npm run build"
"prepublish": "npm run test && npm run build"
},
"author": "Rubens Pinheiro Gonçalves Cavalcante <[email protected]>",
"license": "MIT",
Expand All @@ -41,6 +43,7 @@
"babel-plugin-transform-object-rest-spread": "^6.22.0",
"babel-plugin-transform-regenerator": "^6.22.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.22.0",
"codacy-coverage": "^2.0.0",
"core-js": "^2.4.1",
Expand All @@ -54,6 +57,7 @@
"jasmine-core": "^3.1.0",
"karma": "^2.0.0",
"karma-babel-preprocessor": "^7.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.2",
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/components/ant-path.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,15 @@ export default class AntPath extends FeatureGroup {
}

addLatLng(...args) {
this._path = [...this._path, args];
this[Layers.main].addLatLng(...args);
this[Layers.pulse].addLatLng(...args);

return this;
}

setLatLngs(...args) {
this._path = args;
this[Layers.main].setLatLngs(...args);
this[Layers.pulse].setLatLngs(...args);

Expand Down
13 changes: 9 additions & 4 deletions src/specs/leaflet-ant-path.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import L from "leaflet";
import { AntPath, antPath as antPathFactory } from "../plugin/main";

describe("Creates a leaflet polyline with a 'ant-path' animated flux:", () => {
let spy, fakePolyline, path;
let spy, path;

beforeEach(() => {
fakePolyline = new L.Polyline([0, 0], [1, 1]);
spy = spyOn(L, "Polyline").and.callFake(() => fakePolyline);
path = [L.latLng(0, 0), L.latLng(1, 1)];
});

it("Should use two polylines to stack in a animation", () => {
const fakePolyline = L.polyline(path);
spy = spyOn(L, "Polyline").and.callFake(() => fakePolyline);

new AntPath([0, 0]);
expect(L.Polyline).toHaveBeenCalled();
expect(spy.calls.count()).toBe(2);
Expand Down Expand Up @@ -97,7 +98,8 @@ describe("Creates a leaflet polyline with a 'ant-path' animated flux:", () => {
describe("Should follow all the L.Polygon interface:", () => {
const options = { color: "white", pulseColor: "red" };
const samplePath = [L.latLng(1, 2), L.latLng(3, 4)];
const antPath = new AntPath(samplePath, options);
let antPath;
beforeEach(() => antPath = new AntPath(samplePath, options));

it("Should be able to provide the current latLngs", () => {
expect(antPath.getLatLngs()).toEqual(samplePath);
Expand Down Expand Up @@ -139,7 +141,10 @@ describe("Creates a leaflet polyline with a 'ant-path' animated flux:", () => {
});

it("Should be able to redraw the two composite paths", () => {
const fakePolyline = L.polyline(path);
spy = spyOn(L, "Polyline").and.callFake(() => fakePolyline);
spyOn(fakePolyline, "redraw");

new AntPath(path, options).redraw();
expect(fakePolyline.redraw).toHaveBeenCalledTimes(2);
});
Expand Down
31 changes: 30 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,14 @@ babel-plugin-transform-strict-mode@^6.24.1:
babel-runtime "^6.22.0"
babel-types "^6.24.1"

babel-polyfill@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153"
dependencies:
babel-runtime "^6.26.0"
core-js "^2.5.0"
regenerator-runtime "^0.10.5"

babel-preset-es2015@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-preset-es2015/-/babel-preset-es2015-6.22.0.tgz#af5a98ecb35eb8af764ad8a5a05eb36dc4386835"
Expand Down Expand Up @@ -3668,6 +3676,12 @@ from2@^2.1.0, from2@^2.1.1:
inherits "^2.0.1"
readable-stream "^2.0.0"

fs-access@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/fs-access/-/fs-access-1.0.1.tgz#d6a87f262271cefebec30c553407fb995da8777a"
dependencies:
null-check "^1.0.0"

fs-extra@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-1.0.0.tgz#cd3ce5f7e7cb6145883fcae3191e9877f8587950"
Expand Down Expand Up @@ -5162,6 +5176,13 @@ karma-babel-preprocessor@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/karma-babel-preprocessor/-/karma-babel-preprocessor-7.0.0.tgz#18756d818f97a5e88f91902674cd9130177a8dce"

karma-chrome-launcher@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/karma-chrome-launcher/-/karma-chrome-launcher-2.2.0.tgz#cf1b9d07136cc18fe239327d24654c3dbc368acf"
dependencies:
fs-access "^1.0.0"
which "^1.2.1"

karma-coverage@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/karma-coverage/-/karma-coverage-1.1.1.tgz#5aff8b39cf6994dc22de4c84362c76001b637cf6"
Expand Down Expand Up @@ -6334,6 +6355,10 @@ npmlog@^4.0.2:
gauge "~2.7.3"
set-blocking "~2.0.0"

null-check@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/null-check/-/null-check-1.0.0.tgz#977dffd7176012b9ec30d2a39db5cf72a0439edd"

num2fraction@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/num2fraction/-/num2fraction-1.2.2.tgz#6f682b6a027a4e9ddfa4564cd2589d1d4e669ede"
Expand Down Expand Up @@ -7516,6 +7541,10 @@ regenerator-runtime@^0.10.0:
version "0.10.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.1.tgz#257f41961ce44558b18f7814af48c17559f9faeb"

regenerator-runtime@^0.10.5:
version "0.10.5"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658"

regenerator-runtime@^0.11.0, regenerator-runtime@^0.11.1:
version "0.11.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"
Expand Down Expand Up @@ -9371,7 +9400,7 @@ which@1, which@^1.1.1, which@^1.2.9, which@~1.2.10:
dependencies:
isexe "^1.1.1"

which@^1.2.14:
which@^1.2.1, which@^1.2.14:
version "1.3.0"
resolved "https://registry.yarnpkg.com/which/-/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a"
dependencies:
Expand Down

0 comments on commit 00dc278

Please sign in to comment.