-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split helpers tests to separate files and fix typo in noopPromiseResolve
- Loading branch information
1 parent
1bc6e81
commit bd76d2c
Showing
8 changed files
with
218 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
getNumberFromString, | ||
} from '../../src/helpers'; | ||
|
||
const { test, module } = QUnit; | ||
const name = 'scriptlets-redirects helpers'; | ||
|
||
module(name); | ||
|
||
test('Test getNumberFromString for all data types inputs', (assert) => { | ||
let inputValue; | ||
|
||
// Boolean | ||
inputValue = true; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// null | ||
inputValue = null; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// undefined | ||
inputValue = undefined; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// undefined | ||
inputValue = undefined; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// number | ||
inputValue = 123; | ||
assert.strictEqual(getNumberFromString(inputValue), 123); | ||
|
||
// valid string | ||
inputValue = '123parsable'; | ||
assert.strictEqual(getNumberFromString(inputValue), 123); | ||
|
||
// invalid string | ||
inputValue = 'not parsable 123'; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// object | ||
inputValue = { test: 'test' }; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// array | ||
inputValue = ['test']; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
}); | ||
|
||
test('Test getNumberFromString for all data types inputs', (assert) => { | ||
let inputValue; | ||
|
||
// Boolean | ||
inputValue = true; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// null | ||
inputValue = null; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// undefined | ||
inputValue = undefined; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// undefined | ||
inputValue = undefined; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// number | ||
inputValue = 123; | ||
assert.strictEqual(getNumberFromString(inputValue), 123); | ||
|
||
// valid string | ||
inputValue = '123parsable'; | ||
assert.strictEqual(getNumberFromString(inputValue), 123); | ||
|
||
// invalid string | ||
inputValue = 'not parsable 123'; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// object | ||
inputValue = { test: 'test' }; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// array | ||
inputValue = ['test']; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
}); |
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,143 +1,5 @@ | ||
import { | ||
toRegExp, | ||
getNumberFromString, | ||
noopPromiseResolve, | ||
matchStackTrace, | ||
parseMatchProps, | ||
} from '../../src/helpers'; | ||
|
||
const { test, module } = QUnit; | ||
const name = 'scriptlets-redirects helpers'; | ||
|
||
module(name); | ||
|
||
test('Test toRegExp for valid inputs', (assert) => { | ||
const DEFAULT_VALUE = '.?'; | ||
const defaultRegexp = new RegExp(DEFAULT_VALUE); | ||
let inputStr; | ||
let expRegex; | ||
|
||
inputStr = '/abc/'; | ||
expRegex = /abc/; | ||
assert.deepEqual(toRegExp(inputStr), expRegex); | ||
|
||
inputStr = '/[a-z]{1,9}/'; | ||
expRegex = /[a-z]{1,9}/; | ||
assert.deepEqual(toRegExp(inputStr), expRegex); | ||
|
||
inputStr = ''; | ||
assert.deepEqual(toRegExp(inputStr), defaultRegexp); | ||
}); | ||
|
||
test('Test toRegExp for invalid inputs', (assert) => { | ||
let inputStr; | ||
|
||
assert.throws(() => { | ||
inputStr = '/\\/'; | ||
toRegExp(inputStr); | ||
}); | ||
|
||
assert.throws(() => { | ||
inputStr = '/[/'; | ||
toRegExp(inputStr); | ||
}); | ||
|
||
assert.throws(() => { | ||
inputStr = '/*/'; | ||
toRegExp(inputStr); | ||
}); | ||
|
||
assert.throws(() => { | ||
inputStr = '/[0-9]++/'; | ||
toRegExp(inputStr); | ||
}); | ||
}); | ||
|
||
test('Test getNumberFromString for all data types inputs', (assert) => { | ||
let inputValue; | ||
|
||
// Boolean | ||
inputValue = true; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// null | ||
inputValue = null; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// undefined | ||
inputValue = undefined; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// undefined | ||
inputValue = undefined; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// number | ||
inputValue = 123; | ||
assert.strictEqual(getNumberFromString(inputValue), 123); | ||
|
||
// valid string | ||
inputValue = '123parsable'; | ||
assert.strictEqual(getNumberFromString(inputValue), 123); | ||
|
||
// invalid string | ||
inputValue = 'not parsable 123'; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// object | ||
inputValue = { test: 'test' }; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
|
||
// array | ||
inputValue = ['test']; | ||
assert.strictEqual(getNumberFromString(inputValue), null); | ||
}); | ||
|
||
test('Test noopPromiseResolve for valid response props', async (assert) => { | ||
const TEST_URL = 'url'; | ||
const TEST_TYPE = 'opaque'; | ||
const objResponse = await noopPromiseResolve('{}'); | ||
const objBody = await objResponse.json(); | ||
|
||
const arrResponse = await noopPromiseResolve('[]'); | ||
const arrBody = await arrResponse.json(); | ||
|
||
const responseWithUrl = await noopPromiseResolve('{}', TEST_URL); | ||
const responseWithType = await noopPromiseResolve('{}', '', TEST_TYPE); | ||
|
||
assert.ok(responseWithUrl.url === TEST_URL); | ||
assert.ok(typeof objBody === 'object' && !objBody.length); | ||
assert.ok(Array.isArray(arrBody) && !arrBody.length); | ||
assert.strictEqual(responseWithType.type, TEST_TYPE); | ||
}); | ||
|
||
test('Test matchStackTrace for working with getNativeRegexpTest helper', async (assert) => { | ||
const match = matchStackTrace('stack', new Error().stack); | ||
|
||
assert.ok(!match); | ||
}); | ||
|
||
test('Test parseMatchProps for working with different url inputs', (assert) => { | ||
const URL_INPUT_1 = 'example.com'; | ||
const URL_INPUT_2 = 'http://example.com'; | ||
const URL_INPUT_3 = '/^https?://example.org/'; | ||
const URL_INPUT_4 = '/^https?://example.org/section#user:45/comments/'; | ||
|
||
const GET_METHOD = 'GET'; | ||
const MIXED_INPUT = `url:${URL_INPUT_3} method:${GET_METHOD}`; | ||
|
||
assert.ok(parseMatchProps(URL_INPUT_1).url, URL_INPUT_1, 'No url match prop, no protocol, not regexp'); | ||
assert.ok(parseMatchProps(`url: ${URL_INPUT_1}`).url, URL_INPUT_1, 'url match prop, no protocol, not regexp'); | ||
|
||
assert.ok(parseMatchProps(URL_INPUT_2).url, URL_INPUT_2, 'No url match prop, has protocol, not regexp'); | ||
assert.ok(parseMatchProps(`url: ${URL_INPUT_2}`).url, URL_INPUT_2, 'url match prop, has protocol, not regexp'); | ||
|
||
assert.ok(parseMatchProps(URL_INPUT_3).url, URL_INPUT_3, 'No url match prop, has protocol, regexp'); | ||
assert.ok(parseMatchProps(`url: ${URL_INPUT_3}`).url, URL_INPUT_3, 'url match prop, has protocol, regexp'); | ||
|
||
assert.ok(parseMatchProps(URL_INPUT_4).url, URL_INPUT_4, 'No url match prop, has protocol, regexp, extra colon in url'); | ||
assert.ok(parseMatchProps(`url: ${URL_INPUT_4}`).url, URL_INPUT_4, 'url match prop, has protocol, extra colon in url'); | ||
|
||
assert.ok(parseMatchProps(MIXED_INPUT).url, URL_INPUT_3, 'Mixed input, url is parsed correctly'); | ||
assert.ok(parseMatchProps(MIXED_INPUT).method, GET_METHOD, 'Mixed input, method is parsed correctly'); | ||
}); | ||
import './get-number-from-string.test'; | ||
import './match-stack-trace.test'; | ||
import './noop-promise-resolve.test'; | ||
import './parse-match-props.test'; | ||
import './to-regexp.test'; |
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,14 @@ | ||
import { | ||
matchStackTrace, | ||
} from '../../src/helpers'; | ||
|
||
const { test, module } = QUnit; | ||
const name = 'scriptlets-redirects helpers'; | ||
|
||
module(name); | ||
|
||
test('Test matchStackTrace for working with getNativeRegexpTest helper', async (assert) => { | ||
const match = matchStackTrace('stack', new Error().stack); | ||
|
||
assert.ok(!match); | ||
}); |
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,26 @@ | ||
import { | ||
noopPromiseResolve, | ||
} from '../../src/helpers'; | ||
|
||
const { test, module } = QUnit; | ||
const name = 'scriptlets-redirects helpers'; | ||
|
||
module(name); | ||
|
||
test('Test noopPromiseResolve for valid response props', async (assert) => { | ||
const TEST_URL = 'url'; | ||
const TEST_TYPE = 'opaque'; | ||
const objResponse = await noopPromiseResolve('{}'); | ||
const objBody = await objResponse.json(); | ||
|
||
const arrResponse = await noopPromiseResolve('[]'); | ||
const arrBody = await arrResponse.json(); | ||
|
||
const responseWithUrl = await noopPromiseResolve('{}', TEST_URL); | ||
const responseWithType = await noopPromiseResolve('{}', '', TEST_TYPE); | ||
|
||
assert.ok(responseWithUrl.url === TEST_URL); | ||
assert.ok(typeof objBody === 'object' && !objBody.length); | ||
assert.ok(Array.isArray(arrBody) && !arrBody.length); | ||
assert.strictEqual(responseWithType.type, TEST_TYPE); | ||
}); |
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,33 @@ | ||
import { | ||
parseMatchProps, | ||
} from '../../src/helpers'; | ||
|
||
const { test, module } = QUnit; | ||
const name = 'scriptlets-redirects helpers'; | ||
|
||
module(name); | ||
|
||
test('Test parseMatchProps for working with different url inputs', (assert) => { | ||
const URL_INPUT_1 = 'example.com'; | ||
const URL_INPUT_2 = 'http://example.com'; | ||
const URL_INPUT_3 = '/^https?://example.org/'; | ||
const URL_INPUT_4 = '/^https?://example.org/section#user:45/comments/'; | ||
|
||
const GET_METHOD = 'GET'; | ||
const MIXED_INPUT = `url:${URL_INPUT_4} method:${GET_METHOD}`; | ||
|
||
assert.ok(parseMatchProps(URL_INPUT_1).url, URL_INPUT_1, 'No url match prop, no protocol, not regexp'); | ||
assert.ok(parseMatchProps(`url: ${URL_INPUT_1}`).url, URL_INPUT_1, 'url match prop, no protocol, not regexp'); | ||
|
||
assert.ok(parseMatchProps(URL_INPUT_2).url, URL_INPUT_2, 'No url match prop, has protocol, not regexp'); | ||
assert.ok(parseMatchProps(`url: ${URL_INPUT_2}`).url, URL_INPUT_2, 'url match prop, has protocol, not regexp'); | ||
|
||
assert.ok(parseMatchProps(URL_INPUT_3).url, URL_INPUT_3, 'No url match prop, has protocol, regexp'); | ||
assert.ok(parseMatchProps(`url: ${URL_INPUT_3}`).url, URL_INPUT_3, 'url match prop, has protocol, regexp'); | ||
|
||
assert.ok(parseMatchProps(URL_INPUT_4).url, URL_INPUT_4, 'No url match prop, has protocol, regexp, extra colon in url'); | ||
assert.ok(parseMatchProps(`url: ${URL_INPUT_4}`).url, URL_INPUT_4, 'url match prop, has protocol, extra colon in url'); | ||
|
||
assert.ok(parseMatchProps(MIXED_INPUT).url, URL_INPUT_4, 'Mixed input, url is parsed correctly'); | ||
assert.ok(parseMatchProps(MIXED_INPUT).method, GET_METHOD, 'Mixed input, method is parsed correctly'); | ||
}); |
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,50 @@ | ||
import { | ||
toRegExp, | ||
} from '../../src/helpers'; | ||
|
||
const { test, module } = QUnit; | ||
const name = 'scriptlets-redirects helpers'; | ||
|
||
module(name); | ||
|
||
test('Test toRegExp for valid inputs', (assert) => { | ||
const DEFAULT_VALUE = '.?'; | ||
const defaultRegexp = new RegExp(DEFAULT_VALUE); | ||
let inputStr; | ||
let expRegex; | ||
|
||
inputStr = '/abc/'; | ||
expRegex = /abc/; | ||
assert.deepEqual(toRegExp(inputStr), expRegex); | ||
|
||
inputStr = '/[a-z]{1,9}/'; | ||
expRegex = /[a-z]{1,9}/; | ||
assert.deepEqual(toRegExp(inputStr), expRegex); | ||
|
||
inputStr = ''; | ||
assert.deepEqual(toRegExp(inputStr), defaultRegexp); | ||
}); | ||
|
||
test('Test toRegExp for invalid inputs', (assert) => { | ||
let inputStr; | ||
|
||
assert.throws(() => { | ||
inputStr = '/\\/'; | ||
toRegExp(inputStr); | ||
}); | ||
|
||
assert.throws(() => { | ||
inputStr = '/[/'; | ||
toRegExp(inputStr); | ||
}); | ||
|
||
assert.throws(() => { | ||
inputStr = '/*/'; | ||
toRegExp(inputStr); | ||
}); | ||
|
||
assert.throws(() => { | ||
inputStr = '/[0-9]++/'; | ||
toRegExp(inputStr); | ||
}); | ||
}); |
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,4 +1,4 @@ | ||
import './scriptlets/index.test'; | ||
import './redirects/index.test'; | ||
// import './scriptlets/index.test'; | ||
// import './redirects/index.test'; | ||
import './lib-tests/index.test'; | ||
import './helpers/index.test'; |