setup karma testing
This commit is contained in:
parent
5d085b74f5
commit
709e2eb3c0
|
@ -6,3 +6,4 @@ vwd.webinfo
|
||||||
*.crx
|
*.crx
|
||||||
*.pem
|
*.pem
|
||||||
dist
|
dist
|
||||||
|
coverage
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
module.exports = function(config) {
|
||||||
|
config.set({
|
||||||
|
// base path that will be used to resolve all patterns (eg. files, exclude)
|
||||||
|
basePath: '',
|
||||||
|
|
||||||
|
// frameworks to use
|
||||||
|
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||||
|
frameworks: ['jasmine', 'karma-typescript'],
|
||||||
|
|
||||||
|
// list of files / patterns to load in the browser
|
||||||
|
files: [
|
||||||
|
'src/abstractions/**/*.ts',
|
||||||
|
'src/enums/**/*.ts',
|
||||||
|
'src/models/**/*.ts',
|
||||||
|
'src/services/**/*.ts'
|
||||||
|
],
|
||||||
|
|
||||||
|
// list of files to exclude
|
||||||
|
exclude: [
|
||||||
|
],
|
||||||
|
|
||||||
|
// preprocess matching files before serving them to the browser
|
||||||
|
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||||
|
preprocessors: {
|
||||||
|
'**/*.ts': 'karma-typescript'
|
||||||
|
},
|
||||||
|
|
||||||
|
// test results reporter to use
|
||||||
|
// possible values: 'dots', 'progress'
|
||||||
|
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||||
|
reporters: ['progress', 'karma-typescript', 'kjhtml'],
|
||||||
|
|
||||||
|
// web server port
|
||||||
|
port: 9876,
|
||||||
|
|
||||||
|
// enable / disable colors in the output (reporters and logs)
|
||||||
|
colors: true,
|
||||||
|
|
||||||
|
// level of logging
|
||||||
|
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||||
|
logLevel: config.LOG_INFO,
|
||||||
|
|
||||||
|
// start these browsers
|
||||||
|
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
||||||
|
browsers: ['Chrome'],
|
||||||
|
|
||||||
|
// Concurrency level
|
||||||
|
// how many browser should be started simultaneous
|
||||||
|
concurrency: Infinity,
|
||||||
|
|
||||||
|
client:{
|
||||||
|
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||||
|
},
|
||||||
|
|
||||||
|
karmaTypescriptConfig: {
|
||||||
|
tsconfig: './tsconfig.json',
|
||||||
|
compilerOptions: {
|
||||||
|
module: 'CommonJS'
|
||||||
|
},
|
||||||
|
bundlerOptions: {
|
||||||
|
entrypoints: /\.spec\.ts$/
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
40
package.json
40
package.json
|
@ -12,21 +12,36 @@
|
||||||
"url": "https://github.com/bitwarden/jslib"
|
"url": "https://github.com/bitwarden/jslib"
|
||||||
},
|
},
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"module": "src/index.ts",
|
|
||||||
"typings": "src/index.ts",
|
|
||||||
"files": [
|
|
||||||
"src",
|
|
||||||
"dist"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prebuild": "rimraf dist/**/*",
|
"prebuild": "rimraf dist/**/*",
|
||||||
"build": "tsc && typedoc --out dist/docs --target es6 --theme minimal --mode file src",
|
"build": "tsc",
|
||||||
"start": "tsc -watch",
|
"start": "tsc -watch",
|
||||||
"lint": "tslint src/**/*.ts || true",
|
"lint": "tslint src/**/*.ts || true",
|
||||||
"lint:fix": "tslint src/**/*.ts --fix",
|
"lint:fix": "tslint src/**/*.ts --fix",
|
||||||
"pub": "npm run build && npm publish --access public"
|
"test": "karma start --single-run",
|
||||||
|
"test:watch": "karma start"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/jasmine": "^2.8.2",
|
||||||
|
"@types/lunr": "2.1.5",
|
||||||
|
"@types/node": "8.0.19",
|
||||||
|
"@types/node-forge": "0.7.1",
|
||||||
|
"@types/papaparse": "4.1.31",
|
||||||
|
"@types/webcrypto": "0.0.28",
|
||||||
|
"jasmine-core": "^2.8.0",
|
||||||
|
"jasmine-spec-reporter": "^4.2.1",
|
||||||
|
"karma": "^1.7.1",
|
||||||
|
"karma-chrome-launcher": "^2.2.0",
|
||||||
|
"karma-cli": "^1.0.1",
|
||||||
|
"karma-coverage-istanbul-reporter": "^1.3.0",
|
||||||
|
"karma-jasmine": "^1.1.0",
|
||||||
|
"karma-jasmine-html-reporter": "^0.2.2",
|
||||||
|
"karma-typescript": "^3.0.8",
|
||||||
|
"rimraf": "^2.6.2",
|
||||||
|
"tslint": "^5.8.0",
|
||||||
|
"typescript": "^2.7.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
"@angular/animations": "5.2.0",
|
"@angular/animations": "5.2.0",
|
||||||
"@angular/common": "5.2.0",
|
"@angular/common": "5.2.0",
|
||||||
"@angular/compiler": "5.2.0",
|
"@angular/compiler": "5.2.0",
|
||||||
|
@ -37,21 +52,12 @@
|
||||||
"@angular/platform-browser-dynamic": "5.2.0",
|
"@angular/platform-browser-dynamic": "5.2.0",
|
||||||
"@angular/router": "5.2.0",
|
"@angular/router": "5.2.0",
|
||||||
"@angular/upgrade": "5.2.0",
|
"@angular/upgrade": "5.2.0",
|
||||||
"@types/lunr": "2.1.5",
|
|
||||||
"@types/node": "8.0.19",
|
|
||||||
"@types/node-forge": "0.7.1",
|
|
||||||
"@types/papaparse": "4.1.31",
|
|
||||||
"@types/webcrypto": "0.0.28",
|
|
||||||
"angular2-toaster": "4.0.2",
|
"angular2-toaster": "4.0.2",
|
||||||
"angulartics2": "5.0.1",
|
"angulartics2": "5.0.1",
|
||||||
"core-js": "2.4.1",
|
"core-js": "2.4.1",
|
||||||
"lunr": "2.1.6",
|
"lunr": "2.1.6",
|
||||||
"node-forge": "0.7.1",
|
"node-forge": "0.7.1",
|
||||||
"rimraf": "^2.6.2",
|
|
||||||
"rxjs": "5.5.6",
|
"rxjs": "5.5.6",
|
||||||
"tslint": "^5.8.0",
|
|
||||||
"typedoc": "^0.9.0",
|
|
||||||
"typescript": "^2.7.1",
|
|
||||||
"zone.js": "0.8.19"
|
"zone.js": "0.8.19"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { UtilsService } from './utils.service';
|
||||||
|
|
||||||
|
describe('Utils Service', () => {
|
||||||
|
describe('getHostname', () => {
|
||||||
|
it('should fail for invalid urls', () => {
|
||||||
|
expect(UtilsService.getHostname(null)).toBeNull();
|
||||||
|
expect(UtilsService.getHostname(undefined)).toBeNull();
|
||||||
|
expect(UtilsService.getHostname(' ')).toBeNull();
|
||||||
|
expect(UtilsService.getHostname('https://bit!:"_&ward.com')).toBeNull();
|
||||||
|
expect(UtilsService.getHostname('bitwarden')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle valid urls', () => {
|
||||||
|
expect(UtilsService.getHostname('bitwarden.com')).toBe('bitwarden.com');
|
||||||
|
expect(UtilsService.getHostname('https://bitwarden.com')).toBe('bitwarden.com');
|
||||||
|
expect(UtilsService.getHostname('http://bitwarden.com')).toBe('bitwarden.com');
|
||||||
|
expect(UtilsService.getHostname('http://vault.bitwarden.com')).toBe('vault.bitwarden.com');
|
||||||
|
expect(UtilsService.getHostname('https://user:password@bitwarden.com:8080/password/sites?and&query#hash'))
|
||||||
|
.toBe('bitwarden.com');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should support localhost and IP', () => {
|
||||||
|
expect(UtilsService.getHostname('https://localhost')).toBe('localhost');
|
||||||
|
expect(UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('newGuid', () => {
|
||||||
|
it('should create a valid guid', () => {
|
||||||
|
const validGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||||
|
expect(UtilsService.newGuid()).toMatch(validGuid);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue