mirror of https://github.com/jiahaog/Nativefier
Change Mocha to not need a babel build to run (#349)
* Change Mocha to not need a babel build to run - Also add tests around normalizeUrl * PR 359 Apply changes due to comments - Remove babelrc as its in the package.json - Change tdd npm task to use gulp - Remove source map support file from import list for normalizeUrlSpec - Change gulp tdd task to run mocha on first run 359 Apply changes due to comments - Remove babelrc as its in the package.json - Change tdd npm task to use gulp - Remove source map support file from import list for normalizeUrlSpec - Change gulp tdd task to run mocha on first run 359 Apply changes due to comments - Remove babelrc as its in the package.json - Change tdd npm task to use gulp - Remove source map support file from import list for normalizeUrlSpec - Change gulp tdd task to run mocha on first run
This commit is contained in:
parent
b467ac7a51
commit
461c7a38f0
|
@ -2,21 +2,31 @@ import gulp from 'gulp';
|
||||||
import PATHS from './../helpers/src-paths';
|
import PATHS from './../helpers/src-paths';
|
||||||
|
|
||||||
import istanbul from 'gulp-istanbul';
|
import istanbul from 'gulp-istanbul';
|
||||||
|
import {Instrumenter} from 'isparta';
|
||||||
import mocha from 'gulp-mocha';
|
import mocha from 'gulp-mocha';
|
||||||
|
|
||||||
gulp.task('mocha', ['build'], done => {
|
gulp.task('mocha', done => {
|
||||||
gulp.src(PATHS.CLI_DEST_JS)
|
gulp.src([PATHS.CLI_SRC_JS, '!src/cli.js'])
|
||||||
.pipe(istanbul({includeUntested: true}))
|
.pipe(istanbul({
|
||||||
|
instrumenter: Instrumenter,
|
||||||
|
includeUntested: true
|
||||||
|
}))
|
||||||
|
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
|
||||||
.on('finish', () => {
|
.on('finish', () => {
|
||||||
return gulp.src(PATHS.TEST_DEST_JS, {read: false})
|
return gulp.src(PATHS.TEST_SRC, {read: false})
|
||||||
.pipe(mocha())
|
.pipe(mocha({
|
||||||
|
compilers: 'js:babel-core/register',
|
||||||
|
recursive: true
|
||||||
|
}))
|
||||||
.pipe(istanbul.writeReports({
|
.pipe(istanbul.writeReports({
|
||||||
dir: './coverage',
|
dir: './coverage',
|
||||||
reporters: ['lcov'],
|
reporters: ['lcov'],
|
||||||
reportOpts: {dir: './coverage'}
|
reportOpts: {dir: './coverage'}
|
||||||
}))
|
}))
|
||||||
.on('finish', () => {
|
.on('end', done);
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task('tdd', ['mocha'], () => {
|
||||||
|
return gulp.watch(['src/**/*.js', 'test/**/*.js'], ['mocha']);
|
||||||
|
});
|
||||||
|
|
|
@ -13,8 +13,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev-up": "npm install && (cd app && npm install) && npm run build",
|
"dev-up": "npm install && (cd app && npm install) && npm run build",
|
||||||
"test": "gulp test",
|
"test": "gulp test",
|
||||||
|
"tdd": "gulp tdd",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"ci": "gulp test && npm run lint",
|
"ci": "gulp build test && npm run lint",
|
||||||
"clean": "gulp clean",
|
"clean": "gulp clean",
|
||||||
"build": "gulp build",
|
"build": "gulp build",
|
||||||
"watch": "while true ; do gulp watch ; done",
|
"watch": "while true ; do gulp watch ; done",
|
||||||
|
@ -74,6 +75,7 @@
|
||||||
"gulp-istanbul": "^1.1.1",
|
"gulp-istanbul": "^1.1.1",
|
||||||
"gulp-mocha": "^4.3.0",
|
"gulp-mocha": "^4.3.0",
|
||||||
"gulp-sourcemaps": "^2.6.0",
|
"gulp-sourcemaps": "^2.6.0",
|
||||||
|
"isparta": "^4.0.0",
|
||||||
"require-dir": "^0.3.0",
|
"require-dir": "^0.3.0",
|
||||||
"run-sequence": "^1.1.5",
|
"run-sequence": "^1.1.5",
|
||||||
"webpack-stream": "^3.1.0"
|
"webpack-stream": "^3.1.0"
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
import validator from 'validator';
|
import validator from 'validator';
|
||||||
|
|
||||||
function normalizeUrl(testUrl) {
|
function appendProtocol(testUrl) {
|
||||||
// add protocol if protocol not found
|
const parsed = url.parse(testUrl);
|
||||||
let normalized = testUrl;
|
|
||||||
const parsed = url.parse(normalized);
|
|
||||||
if (!parsed.protocol) {
|
if (!parsed.protocol) {
|
||||||
normalized = 'http://' + normalized;
|
return `http://${testUrl}`;
|
||||||
}
|
}
|
||||||
|
return testUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeUrl(testUrl) {
|
||||||
|
const urlWithProtocol = appendProtocol(testUrl);
|
||||||
|
|
||||||
const validatorOptions = {
|
const validatorOptions = {
|
||||||
require_protocol: true,
|
require_protocol: true,
|
||||||
require_tld: false,
|
require_tld: false,
|
||||||
allow_trailing_dot: true // mDNS addresses, https://github.com/jiahaog/nativefier/issues/308
|
allow_trailing_dot: true // mDNS addresses, https://github.com/jiahaog/nativefier/issues/308
|
||||||
};
|
};
|
||||||
if (!validator.isURL(normalized, validatorOptions)) {
|
if (!validator.isURL(urlWithProtocol, validatorOptions)) {
|
||||||
throw `Your Url: "${normalized}" is invalid!`;
|
throw `Your Url: "${urlWithProtocol}" is invalid!`;
|
||||||
}
|
}
|
||||||
return normalized;
|
return urlWithProtocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default normalizeUrl;
|
export default normalizeUrl;
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import normalizeUrl from '../../../src/options/normalizeUrl';
|
||||||
|
import chai from 'chai';
|
||||||
|
const assert = chai.assert;
|
||||||
|
const expect = chai.expect;
|
||||||
|
|
||||||
|
describe('Normalize URL', () => {
|
||||||
|
|
||||||
|
describe('given a valid URL without a protocol', () => {
|
||||||
|
it('should allow the url', () => {
|
||||||
|
assert.equal(normalizeUrl('http://www.google.com'), 'http://www.google.com');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('given a valid URL without a protocol', () => {
|
||||||
|
it('should allow the url and prepend the HTTP protocol', () => {
|
||||||
|
assert.equal(normalizeUrl('www.google.com'), 'http://www.google.com');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('given an invalid URL', () => {
|
||||||
|
it('should throw an exception', () => {
|
||||||
|
expect(() => normalizeUrl('http://ssddfoo bar')).to.throw('Your Url: "http://ssddfoo bar" is invalid!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue