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 istanbul from 'gulp-istanbul';
|
||||
import {Instrumenter} from 'isparta';
|
||||
import mocha from 'gulp-mocha';
|
||||
|
||||
gulp.task('mocha', ['build'], done => {
|
||||
gulp.src(PATHS.CLI_DEST_JS)
|
||||
.pipe(istanbul({includeUntested: true}))
|
||||
gulp.task('mocha', done => {
|
||||
gulp.src([PATHS.CLI_SRC_JS, '!src/cli.js'])
|
||||
.pipe(istanbul({
|
||||
instrumenter: Instrumenter,
|
||||
includeUntested: true
|
||||
}))
|
||||
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
|
||||
.on('finish', () => {
|
||||
return gulp.src(PATHS.TEST_DEST_JS, {read: false})
|
||||
.pipe(mocha())
|
||||
return gulp.src(PATHS.TEST_SRC, {read: false})
|
||||
.pipe(mocha({
|
||||
compilers: 'js:babel-core/register',
|
||||
recursive: true
|
||||
}))
|
||||
.pipe(istanbul.writeReports({
|
||||
dir: './coverage',
|
||||
reporters: ['lcov'],
|
||||
reportOpts: {dir: './coverage'}
|
||||
}))
|
||||
.on('finish', () => {
|
||||
done();
|
||||
});
|
||||
.on('end', done);
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('tdd', ['mocha'], () => {
|
||||
return gulp.watch(['src/**/*.js', 'test/**/*.js'], ['mocha']);
|
||||
});
|
||||
|
|
|
@ -13,8 +13,9 @@
|
|||
"scripts": {
|
||||
"dev-up": "npm install && (cd app && npm install) && npm run build",
|
||||
"test": "gulp test",
|
||||
"tdd": "gulp tdd",
|
||||
"lint": "eslint .",
|
||||
"ci": "gulp test && npm run lint",
|
||||
"ci": "gulp build test && npm run lint",
|
||||
"clean": "gulp clean",
|
||||
"build": "gulp build",
|
||||
"watch": "while true ; do gulp watch ; done",
|
||||
|
@ -74,6 +75,7 @@
|
|||
"gulp-istanbul": "^1.1.1",
|
||||
"gulp-mocha": "^4.3.0",
|
||||
"gulp-sourcemaps": "^2.6.0",
|
||||
"isparta": "^4.0.0",
|
||||
"require-dir": "^0.3.0",
|
||||
"run-sequence": "^1.1.5",
|
||||
"webpack-stream": "^3.1.0"
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
import url from 'url';
|
||||
import validator from 'validator';
|
||||
|
||||
function normalizeUrl(testUrl) {
|
||||
// add protocol if protocol not found
|
||||
let normalized = testUrl;
|
||||
const parsed = url.parse(normalized);
|
||||
function appendProtocol(testUrl) {
|
||||
const parsed = url.parse(testUrl);
|
||||
if (!parsed.protocol) {
|
||||
normalized = 'http://' + normalized;
|
||||
return `http://${testUrl}`;
|
||||
}
|
||||
return testUrl;
|
||||
}
|
||||
|
||||
function normalizeUrl(testUrl) {
|
||||
const urlWithProtocol = appendProtocol(testUrl);
|
||||
|
||||
const validatorOptions = {
|
||||
require_protocol: true,
|
||||
require_tld: false,
|
||||
allow_trailing_dot: true // mDNS addresses, https://github.com/jiahaog/nativefier/issues/308
|
||||
};
|
||||
if (!validator.isURL(normalized, validatorOptions)) {
|
||||
throw `Your Url: "${normalized}" is invalid!`;
|
||||
if (!validator.isURL(urlWithProtocol, validatorOptions)) {
|
||||
throw `Your Url: "${urlWithProtocol}" is invalid!`;
|
||||
}
|
||||
return normalized;
|
||||
return urlWithProtocol;
|
||||
}
|
||||
|
||||
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