5 changed files with 5303 additions and 360 deletions
@ -0,0 +1,65 @@
@@ -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$/ |
||||
} |
||||
}, |
||||
}) |
||||
} |
||||
@ -0,0 +1,34 @@
@@ -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