-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
176283b
commit df25433
Showing
11 changed files
with
244 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`findPort cli utility function should throw the error when the port isn't found 1`] = `"No open ports found in between 8080 and 8085"`; | ||
exports[`findPort util should throws the error when the port isn't found 1`] = `"No open ports found in between 8080 and 8085"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const createLogger = require('../../../lib/utils/createLogger'); | ||
|
||
describe('createLogger util', () => { | ||
it('should create logger without options', () => { | ||
const logger = createLogger(); | ||
|
||
expect(logger.name).toBe('wds'); | ||
expect(logger.currentLevel).toBe(2); | ||
}); | ||
|
||
it('should create logger with logLevel option (debug)', () => { | ||
const logger = createLogger({ logLevel: 'debug' }); | ||
|
||
expect(logger.name).toBe('wds'); | ||
expect(logger.currentLevel).toBe(1); | ||
}); | ||
|
||
it('should create logger with logLevel option (warn)', () => { | ||
const logger = createLogger({ logLevel: 'warn' }); | ||
|
||
expect(logger.name).toBe('wds'); | ||
expect(logger.currentLevel).toBe(3); | ||
}); | ||
|
||
it('should create logger with noInfo option', () => { | ||
const logger = createLogger({ noInfo: true }); | ||
|
||
expect(logger.name).toBe('wds'); | ||
expect(logger.currentLevel).toBe(3); | ||
}); | ||
|
||
it('should create logger with quiet option', () => { | ||
const logger = createLogger({ quiet: true }); | ||
|
||
expect(logger.name).toBe('wds'); | ||
expect(logger.currentLevel).toBe(5); | ||
}); | ||
|
||
it('should create logger with logTime option', () => { | ||
const logger = createLogger({ logTime: true }); | ||
|
||
expect(logger.name).toBe('wds'); | ||
expect(logger.currentLevel).toBe(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
const defaultPort = require('../../../lib/utils/defaultPort'); | ||
|
||
describe('defaultPort util', () => { | ||
it('should return value', () => { | ||
expect(defaultPort).toBe(8080); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const defaultTo = require('../../../lib/utils/defaultTo'); | ||
|
||
const noop = () => {}; | ||
const array = [1, 2, 3]; | ||
|
||
describe('defaultTo util', () => { | ||
it('should returns value', () => { | ||
expect(defaultTo(0, 200)).toBe(0); | ||
expect(defaultTo(100, 200)).toBe(100); | ||
expect(defaultTo('', 200)).toBe(''); | ||
expect(defaultTo('string', 200)).toBe('string'); | ||
expect(defaultTo(noop, 200)).toBe(noop); | ||
expect(defaultTo(array, 200)).toEqual(array); | ||
expect(defaultTo(null, 200)).toBe(200); | ||
// eslint-disable-next-line no-undefined | ||
expect(defaultTo(undefined, 200)).toBe(200); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
'use strict'; | ||
|
||
const opn = require('opn'); | ||
const runOpen = require('../../../lib/utils/runOpen'); | ||
|
||
jest.mock('opn'); | ||
|
||
describe('runOpen util', () => { | ||
afterEach(() => { | ||
opn.mockClear(); | ||
}); | ||
|
||
describe('should open browser', () => { | ||
beforeEach(() => { | ||
opn.mockImplementation(() => Promise.resolve()); | ||
}); | ||
|
||
it('on specify URL', () => { | ||
return runOpen('https://example.com', {}, console).then(() => { | ||
expect(opn.mock.calls[0]).toEqual(['https://example.com', {}]); | ||
}); | ||
}); | ||
|
||
it('on specify URL with page', () => { | ||
return runOpen( | ||
'https://example.com', | ||
{ openPage: '/index.html' }, | ||
console | ||
).then(() => { | ||
expect(opn.mock.calls[0]).toEqual([ | ||
'https://example.com/index.html', | ||
{}, | ||
]); | ||
}); | ||
}); | ||
|
||
it('on specify URL in Google Chrome', () => { | ||
return runOpen( | ||
'https://example.com', | ||
{ open: 'Google Chrome' }, | ||
console | ||
).then(() => { | ||
expect(opn.mock.calls[0]).toEqual([ | ||
'https://example.com', | ||
{ app: 'Google Chrome' }, | ||
]); | ||
}); | ||
}); | ||
|
||
it('on specify URL with page in Google Chrome ', () => { | ||
return runOpen( | ||
'https://example.com', | ||
{ open: 'Google Chrome', openPage: '/index.html' }, | ||
console | ||
).then(() => { | ||
expect(opn.mock.calls[0]).toEqual([ | ||
'https://example.com/index.html', | ||
{ app: 'Google Chrome' }, | ||
]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('should not open browser', () => { | ||
const logMock = { warn: jest.fn() }; | ||
|
||
beforeEach(() => { | ||
opn.mockImplementation(() => Promise.reject()); | ||
}); | ||
|
||
afterEach(() => { | ||
logMock.warn.mockClear(); | ||
}); | ||
|
||
it('on specify URL and log error', () => { | ||
return runOpen('https://example.com', {}, logMock).then(() => { | ||
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot( | ||
`"Unable to open browser. If you are running in a headless environment, please do not use the --open flag"` | ||
); | ||
expect(opn.mock.calls[0]).toEqual(['https://example.com', {}]); | ||
}); | ||
}); | ||
|
||
it('on specify URL with page and log error', () => { | ||
return runOpen( | ||
'https://example.com', | ||
{ openPage: '/index.html' }, | ||
logMock | ||
).then(() => { | ||
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot( | ||
`"Unable to open browser. If you are running in a headless environment, please do not use the --open flag"` | ||
); | ||
expect(opn.mock.calls[0]).toEqual([ | ||
'https://example.com/index.html', | ||
{}, | ||
]); | ||
}); | ||
}); | ||
|
||
it('on specify URL in Google Chrome and log error', () => { | ||
return runOpen( | ||
'https://example.com', | ||
{ open: 'Google Chrome' }, | ||
logMock | ||
).then(() => { | ||
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot( | ||
`"Unable to open browser: Google Chrome. If you are running in a headless environment, please do not use the --open flag"` | ||
); | ||
expect(opn.mock.calls[0]).toEqual([ | ||
'https://example.com', | ||
{ | ||
app: 'Google Chrome', | ||
}, | ||
]); | ||
}); | ||
}); | ||
|
||
it('on specify URL with page in Google Chrome and log error ', () => { | ||
return runOpen( | ||
'https://example.com', | ||
{ open: 'Google Chrome', openPage: '/index.html' }, | ||
logMock | ||
).then(() => { | ||
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot( | ||
`"Unable to open browser: Google Chrome. If you are running in a headless environment, please do not use the --open flag"` | ||
); | ||
expect(opn.mock.calls[0]).toEqual([ | ||
'https://example.com/index.html', | ||
{ app: 'Google Chrome' }, | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const tryParseInt = require('../../../lib/utils/tryParseInt'); | ||
|
||
describe('tryParseInt util', () => { | ||
it('should parser number as number', () => { | ||
expect(tryParseInt(1)).toBe(1); | ||
}); | ||
|
||
it('should parser string as number', () => { | ||
expect(tryParseInt('1')).toBe(1); | ||
}); | ||
|
||
it('should parser undefined as null', () => { | ||
// eslint-disable-next-line no-undefined | ||
expect(tryParseInt(undefined)).toBe(null); | ||
}); | ||
|
||
it('should parser NaN as null', () => { | ||
expect(tryParseInt(NaN)).toBe(null); | ||
}); | ||
}); |