@ni/jasmine-parameterized 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/parameterize-spec.d.ts +29 -0
- package/dist/esm/parameterize-spec.js +35 -0
- package/dist/esm/parameterize-spec.js.map +1 -0
- package/dist/esm/parameterize-suite.d.ts +34 -0
- package/dist/esm/parameterize-suite.js +40 -0
- package/dist/esm/parameterize-suite.js.map +1 -0
- package/dist/esm/parameterize.d.ts +30 -0
- package/dist/esm/parameterize.js +25 -0
- package/dist/esm/parameterize.js.map +1 -0
- package/dist/esm/types.d.ts +30 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +1 -1
- package/dist/esm/parameterized.d.ts +0 -72
- package/dist/esm/parameterized.js +0 -75
- package/dist/esm/parameterized.js.map +0 -1
package/README.md
CHANGED
|
@@ -40,3 +40,37 @@ describe('Different rains', () => {
|
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
```
|
|
43
|
+
|
|
44
|
+
### `parameterizeSuite`
|
|
45
|
+
|
|
46
|
+
Use `parameterizeSuite` to create a parameterized test suite using an array of test scenarios with names.
|
|
47
|
+
|
|
48
|
+
In the following example:
|
|
49
|
+
|
|
50
|
+
- the suite named `cats-and-dogs` is focused for debugging
|
|
51
|
+
- the suite named `frogs` is configured to always be disabled
|
|
52
|
+
- the suite named `men` will run normally as it has no override
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { parameterizeSuite } from '@ni/jasmine-parameterized';
|
|
56
|
+
const rainTests = [
|
|
57
|
+
{ name: 'cats-and-dogs', type: 'idiom' },
|
|
58
|
+
{ name: 'frogs' type: 'idiom'},
|
|
59
|
+
{ name: 'men', type: 'lyrics'}
|
|
60
|
+
] as const;
|
|
61
|
+
parameterizeSuite(rainTests, (suite, name, value) => {
|
|
62
|
+
suite(`with ${name}`, () => {
|
|
63
|
+
it('expect type to be defined', () => {
|
|
64
|
+
expect(value.type).toBeDefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('expect type to have a non-zero length', () => {
|
|
68
|
+
const length = value.type.length;
|
|
69
|
+
expect(length).toBeGreaterThan(0);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}, {
|
|
73
|
+
'cats-and-dogs': fdescribe,
|
|
74
|
+
frogs: xdescribe
|
|
75
|
+
});
|
|
76
|
+
```
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { parameterizeSpec } from './
|
|
1
|
+
export { parameterizeSpec } from './parameterize-spec.js';
|
|
2
|
+
export { parameterizeSuite } from './parameterize-suite.js';
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC","sourcesContent":["export { parameterizeSpec } from './parameterize-spec.js';\nexport { parameterizeSuite } from './parameterize-suite.js';\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ObjectFromNamedList, Spec, SpecOverride } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Used to create a parameterized test using an array of tests with names.
|
|
4
|
+
* In the following example:
|
|
5
|
+
* - the test named `cats-and-dogs` is focused for debugging
|
|
6
|
+
* - the test named `frogs` is configured to always be disabled
|
|
7
|
+
* - the test named `men` will run normally as it has no override
|
|
8
|
+
* @example
|
|
9
|
+
* const rainTests = [
|
|
10
|
+
* { name: 'cats-and-dogs', type: 'idiom' },
|
|
11
|
+
* { name: 'frogs' type: 'idiom'},
|
|
12
|
+
* { name: 'men', type: 'lyrics'}
|
|
13
|
+
* ] as const;
|
|
14
|
+
* describe('Different rains', () => {
|
|
15
|
+
* parameterizeSpec(rainTests, (spec, name, value) => {
|
|
16
|
+
* spec(`of type ${name} exist`, () => {
|
|
17
|
+
* expect(value.type).toBeDefined();
|
|
18
|
+
* });
|
|
19
|
+
* }, {
|
|
20
|
+
* 'cats-and-dogs': fit,
|
|
21
|
+
* frogs: xit
|
|
22
|
+
* });
|
|
23
|
+
* });
|
|
24
|
+
*/
|
|
25
|
+
export declare const parameterizeSpec: <T extends readonly {
|
|
26
|
+
name: string;
|
|
27
|
+
}[]>(list: T, test: (spec: Spec, name: T extends readonly {
|
|
28
|
+
name: infer U;
|
|
29
|
+
}[] ? U : never, value: T[number]) => void, specOverrides?: { [P in keyof ObjectFromNamedList<T>]?: SpecOverride | undefined; } | undefined) => void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { parameterize } from './parameterize.js';
|
|
2
|
+
/**
|
|
3
|
+
* Used to create a parameterized test using an array of tests with names.
|
|
4
|
+
* In the following example:
|
|
5
|
+
* - the test named `cats-and-dogs` is focused for debugging
|
|
6
|
+
* - the test named `frogs` is configured to always be disabled
|
|
7
|
+
* - the test named `men` will run normally as it has no override
|
|
8
|
+
* @example
|
|
9
|
+
* const rainTests = [
|
|
10
|
+
* { name: 'cats-and-dogs', type: 'idiom' },
|
|
11
|
+
* { name: 'frogs' type: 'idiom'},
|
|
12
|
+
* { name: 'men', type: 'lyrics'}
|
|
13
|
+
* ] as const;
|
|
14
|
+
* describe('Different rains', () => {
|
|
15
|
+
* parameterizeSpec(rainTests, (spec, name, value) => {
|
|
16
|
+
* spec(`of type ${name} exist`, () => {
|
|
17
|
+
* expect(value.type).toBeDefined();
|
|
18
|
+
* });
|
|
19
|
+
* }, {
|
|
20
|
+
* 'cats-and-dogs': fit,
|
|
21
|
+
* frogs: xit
|
|
22
|
+
* });
|
|
23
|
+
* });
|
|
24
|
+
*/
|
|
25
|
+
export const parameterizeSpec = (list, test, specOverrides) => {
|
|
26
|
+
const testCases = list.reduce((result, entry) => {
|
|
27
|
+
if (result[entry.name]) {
|
|
28
|
+
throw new Error(`Duplicate name found in test case list: ${entry.name}. Make sure all test names are unique.`);
|
|
29
|
+
}
|
|
30
|
+
result[entry.name] = entry;
|
|
31
|
+
return result;
|
|
32
|
+
}, {});
|
|
33
|
+
parameterize('spec', testCases, test, specOverrides);
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=parameterize-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameterize-spec.js","sourceRoot":"","sources":["../../src/parameterize-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC5B,IAAO,EACP,IAIS,EACT,aAEC,EACG,EAAE;IACN,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CACzB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACd,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;YACpB,MAAM,IAAI,KAAK,CACX,2CAA2C,KAAK,CAAC,IAAI,wCAAwC,CAChG,CAAC;SACL;QACD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC3B,OAAO,MAAM,CAAC;IAClB,CAAC,EACD,EAAE,CACqB,CAAC;IAC5B,YAAY,CAAyB,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;AACjF,CAAC,CAAC","sourcesContent":["import { parameterize } from './parameterize.js';\nimport { ObjectFromNamedList, Spec, SpecOverride } from './types.js';\n\n/**\n * Used to create a parameterized test using an array of tests with names.\n * In the following example:\n * - the test named `cats-and-dogs` is focused for debugging\n * - the test named `frogs` is configured to always be disabled\n * - the test named `men` will run normally as it has no override\n * @example\n * const rainTests = [\n * { name: 'cats-and-dogs', type: 'idiom' },\n * { name: 'frogs' type: 'idiom'},\n * { name: 'men', type: 'lyrics'}\n * ] as const;\n * describe('Different rains', () => {\n * parameterizeSpec(rainTests, (spec, name, value) => {\n * spec(`of type ${name} exist`, () => {\n * expect(value.type).toBeDefined();\n * });\n * }, {\n * 'cats-and-dogs': fit,\n * frogs: xit\n * });\n * });\n */\nexport const parameterizeSpec = <T extends readonly { name: string }[]>(\n list: T,\n test: (\n spec: Spec,\n name: keyof ObjectFromNamedList<T>,\n value: T[number]\n ) => void,\n specOverrides?: {\n [P in keyof ObjectFromNamedList<T>]?: SpecOverride;\n }\n): void => {\n const testCases = list.reduce<{ [key: string]: { name: string } }>(\n (result, entry) => {\n if (result[entry.name]) {\n throw new Error(\n `Duplicate name found in test case list: ${entry.name}. Make sure all test names are unique.`\n );\n }\n result[entry.name] = entry;\n return result;\n },\n {}\n ) as ObjectFromNamedList<T>;\n parameterize<ObjectFromNamedList<T>>('spec', testCases, test, specOverrides);\n};\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ObjectFromNamedList, Suite, SuiteOverride } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Used to create a parameterized suite using an array of test scenarios with names.
|
|
4
|
+
* In the following example:
|
|
5
|
+
* - the suite named `cats-and-dogs` is focused for debugging
|
|
6
|
+
* - the suite named `frogs` is configured to always be disabled
|
|
7
|
+
* - the suite named `men` will run normally as it has no override
|
|
8
|
+
* @example
|
|
9
|
+
* const rainTests = [
|
|
10
|
+
* { name: 'cats-and-dogs', type: 'idiom' },
|
|
11
|
+
* { name: 'frogs' type: 'idiom'},
|
|
12
|
+
* { name: 'men', type: 'lyrics'}
|
|
13
|
+
* ] as const;
|
|
14
|
+
* parameterizeSuite(rainTests, (suite, name, value) => {
|
|
15
|
+
* suite(`with ${name}`, () => {
|
|
16
|
+
* it('expect type to be defined', () => {
|
|
17
|
+
* expect(value.type).toBeDefined();
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* it('expect type to have a non-zero length', () => {
|
|
21
|
+
* const length = value.type.length;
|
|
22
|
+
* expect(length).toBeGreaterThan(0);
|
|
23
|
+
* });
|
|
24
|
+
* });
|
|
25
|
+
* }, {
|
|
26
|
+
* 'cats-and-dogs': fdescribe,
|
|
27
|
+
* frogs: xdescribe
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
export declare const parameterizeSuite: <T extends readonly {
|
|
31
|
+
name: string;
|
|
32
|
+
}[]>(list: T, test: (suite: Suite, name: T extends readonly {
|
|
33
|
+
name: infer U;
|
|
34
|
+
}[] ? U : never, value: T[number]) => void, specOverrides?: { [P in keyof ObjectFromNamedList<T>]?: SuiteOverride | undefined; } | undefined) => void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { parameterize } from './parameterize.js';
|
|
2
|
+
/**
|
|
3
|
+
* Used to create a parameterized suite using an array of test scenarios with names.
|
|
4
|
+
* In the following example:
|
|
5
|
+
* - the suite named `cats-and-dogs` is focused for debugging
|
|
6
|
+
* - the suite named `frogs` is configured to always be disabled
|
|
7
|
+
* - the suite named `men` will run normally as it has no override
|
|
8
|
+
* @example
|
|
9
|
+
* const rainTests = [
|
|
10
|
+
* { name: 'cats-and-dogs', type: 'idiom' },
|
|
11
|
+
* { name: 'frogs' type: 'idiom'},
|
|
12
|
+
* { name: 'men', type: 'lyrics'}
|
|
13
|
+
* ] as const;
|
|
14
|
+
* parameterizeSuite(rainTests, (suite, name, value) => {
|
|
15
|
+
* suite(`with ${name}`, () => {
|
|
16
|
+
* it('expect type to be defined', () => {
|
|
17
|
+
* expect(value.type).toBeDefined();
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* it('expect type to have a non-zero length', () => {
|
|
21
|
+
* const length = value.type.length;
|
|
22
|
+
* expect(length).toBeGreaterThan(0);
|
|
23
|
+
* });
|
|
24
|
+
* });
|
|
25
|
+
* }, {
|
|
26
|
+
* 'cats-and-dogs': fdescribe,
|
|
27
|
+
* frogs: xdescribe
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
export const parameterizeSuite = (list, test, specOverrides) => {
|
|
31
|
+
const testCases = list.reduce((result, entry) => {
|
|
32
|
+
if (result[entry.name]) {
|
|
33
|
+
throw new Error(`Duplicate name found in test suite list: ${entry.name}. Make sure all test suite names are unique.`);
|
|
34
|
+
}
|
|
35
|
+
result[entry.name] = entry;
|
|
36
|
+
return result;
|
|
37
|
+
}, {});
|
|
38
|
+
parameterize('suite', testCases, test, specOverrides);
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=parameterize-suite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameterize-suite.js","sourceRoot":"","sources":["../../src/parameterize-suite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BE;AACF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC7B,IAAO,EACP,IAIS,EACT,aAEC,EACG,EAAE;IACN,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CACzB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACd,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;YACpB,MAAM,IAAI,KAAK,CACX,4CAA4C,KAAK,CAAC,IAAI,8CAA8C,CACvG,CAAC;SACL;QACD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC3B,OAAO,MAAM,CAAC;IAClB,CAAC,EACD,EAAE,CACqB,CAAC;IAC5B,YAAY,CAAyB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;AAClF,CAAC,CAAC","sourcesContent":["import { parameterize } from './parameterize.js';\nimport { ObjectFromNamedList, Suite, SuiteOverride } from './types.js';\n\n/**\n * Used to create a parameterized suite using an array of test scenarios with names.\n * In the following example:\n * - the suite named `cats-and-dogs` is focused for debugging\n * - the suite named `frogs` is configured to always be disabled\n * - the suite named `men` will run normally as it has no override\n * @example\n* const rainTests = [\n* { name: 'cats-and-dogs', type: 'idiom' },\n* { name: 'frogs' type: 'idiom'},\n* { name: 'men', type: 'lyrics'}\n* ] as const;\n* parameterizeSuite(rainTests, (suite, name, value) => {\n* suite(`with ${name}`, () => {\n* it('expect type to be defined', () => {\n* expect(value.type).toBeDefined();\n* });\n*\n* it('expect type to have a non-zero length', () => {\n* const length = value.type.length;\n* expect(length).toBeGreaterThan(0);\n* });\n* });\n* }, {\n* 'cats-and-dogs': fdescribe,\n* frogs: xdescribe\n* });\n*/\nexport const parameterizeSuite = <T extends readonly { name: string }[]>(\n list: T,\n test: (\n suite: Suite,\n name: keyof ObjectFromNamedList<T>,\n value: T[number]\n ) => void,\n specOverrides?: {\n [P in keyof ObjectFromNamedList<T>]?: SuiteOverride;\n }\n): void => {\n const testCases = list.reduce<{ [key: string]: { name: string } }>(\n (result, entry) => {\n if (result[entry.name]) {\n throw new Error(\n `Duplicate name found in test suite list: ${entry.name}. Make sure all test suite names are unique.`\n );\n }\n result[entry.name] = entry;\n return result;\n },\n {}\n ) as ObjectFromNamedList<T>;\n parameterize<ObjectFromNamedList<T>>('suite', testCases, test, specOverrides);\n};\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Spec, SpecOverride, Suite, SuiteOverride } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Used to create a parameterized test or suite using an object of names and arbitrary test values.
|
|
4
|
+
* In the following example:
|
|
5
|
+
* - the test named `catsAndDogs` is focused for debugging
|
|
6
|
+
* - the test named `frogs` is configured to always be disabled
|
|
7
|
+
* - the test named `men` will run normally as it has no override
|
|
8
|
+
* @example
|
|
9
|
+
* const rainTests = {
|
|
10
|
+
* catsAndDogs: 'idiom',
|
|
11
|
+
* frogs: 'idiom',
|
|
12
|
+
* men: 'lyrics'
|
|
13
|
+
* } as const;
|
|
14
|
+
* describe('Different rains', () => {
|
|
15
|
+
* parameterize('spec', rainTests, (spec, name, value) => {
|
|
16
|
+
* spec(`of type ${name} exist`, () => {
|
|
17
|
+
* expect(value).toBeDefined();
|
|
18
|
+
* });
|
|
19
|
+
* }, {
|
|
20
|
+
* catsAndDogs: fit,
|
|
21
|
+
* frogs: xit
|
|
22
|
+
* });
|
|
23
|
+
* });
|
|
24
|
+
*/
|
|
25
|
+
export declare function parameterize<T extends object>(testType: 'spec', testCases: T, test: (spec: Spec, name: keyof T, value: T[keyof T]) => void, overrides?: {
|
|
26
|
+
[P in keyof T]?: SpecOverride;
|
|
27
|
+
}): void;
|
|
28
|
+
export declare function parameterize<T extends object>(testType: 'suite', testCases: T, test: (spec: Suite, name: keyof T, value: T[keyof T]) => void, overrides?: {
|
|
29
|
+
[P in keyof T]?: SuiteOverride;
|
|
30
|
+
}): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function parameterize(testType, testCases, test, overrides) {
|
|
2
|
+
const testCaseNames = Object.keys(testCases);
|
|
3
|
+
if (overrides) {
|
|
4
|
+
const overrideNames = Object.keys(overrides);
|
|
5
|
+
if (!overrideNames.every(overrideName => testCaseNames.includes(overrideName))) {
|
|
6
|
+
throw new Error('Parameterized test override names must match test case name');
|
|
7
|
+
}
|
|
8
|
+
if (testType === 'spec'
|
|
9
|
+
// eslint-disable-next-line no-restricted-globals
|
|
10
|
+
&& !overrideNames.every(overrideName => [fit, xit].includes(overrides[overrideName]))) {
|
|
11
|
+
throw new Error('Must configure override with one of the jasmine spec functions: fit or xit');
|
|
12
|
+
}
|
|
13
|
+
if (testType === 'suite'
|
|
14
|
+
// eslint-disable-next-line no-restricted-globals
|
|
15
|
+
&& !overrideNames.every(overrideName => [fdescribe, xdescribe].includes(overrides[overrideName]))) {
|
|
16
|
+
throw new Error('Must configure override with one of the jasmine suite functions: fdescribe or xdescribe');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
testCaseNames.forEach(testCaseName => {
|
|
20
|
+
const defaultTest = testType === 'spec' ? it : describe;
|
|
21
|
+
const spec = overrides?.[testCaseName] ?? defaultTest;
|
|
22
|
+
test(spec, testCaseName, testCases[testCaseName]);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=parameterize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameterize.js","sourceRoot":"","sources":["../../src/parameterize.ts"],"names":[],"mappings":"AAyCA,MAAM,UAAU,YAAY,CACxB,QAA0B,EAC1B,SAAY,EACZ,IAAyD,EACzD,SAEC;IAED,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAgB,CAAC;IAC5D,IAAI,SAAS,EAAE;QACX,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAC7B,SAAS,CACkB,CAAC;QAChC,IACI,CAAC,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,EAC5E;YACE,MAAM,IAAI,KAAK,CACX,6DAA6D,CAChE,CAAC;SACL;QACD,IACI,QAAQ,KAAK,MAAM;YACnB,iDAAiD;eAC9C,CAAC,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,CAAS,CAAC,CAAC,EAC/F;YACE,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;SACjG;QACD,IACI,QAAQ,KAAK,OAAO;YACpB,iDAAiD;eAC9C,CAAC,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,CAAU,CAAC,CAAC,EAC5G;YACE,MAAM,IAAI,KAAK,CACX,yFAAyF,CAC5F,CAAC;SACL;KACJ;IACD,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACjC,MAAM,WAAW,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QACxD,MAAM,IAAI,GAAG,SAAS,EAAE,CAAC,YAAY,CAAC,IAAI,WAAW,CAAC;QACtD,IAAI,CAAC,IAAS,EAAE,YAAY,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { Spec, SpecOverride, Suite, SuiteOverride } from './types.js';\n\n/**\n * Used to create a parameterized test or suite using an object of names and arbitrary test values.\n * In the following example:\n * - the test named `catsAndDogs` is focused for debugging\n * - the test named `frogs` is configured to always be disabled\n * - the test named `men` will run normally as it has no override\n * @example\n * const rainTests = {\n * catsAndDogs: 'idiom',\n * frogs: 'idiom',\n * men: 'lyrics'\n * } as const;\n * describe('Different rains', () => {\n * parameterize('spec', rainTests, (spec, name, value) => {\n * spec(`of type ${name} exist`, () => {\n * expect(value).toBeDefined();\n * });\n * }, {\n * catsAndDogs: fit,\n * frogs: xit\n * });\n * });\n */\nexport function parameterize<T extends object>(\n testType: 'spec',\n testCases: T,\n test: (spec: Spec, name: keyof T, value: T[keyof T]) => void,\n overrides?: {\n [P in keyof T]?: SpecOverride;\n }\n): void;\nexport function parameterize<T extends object>(\n testType: 'suite',\n testCases: T,\n test: (spec: Suite, name: keyof T, value: T[keyof T]) => void,\n overrides?: {\n [P in keyof T]?: SuiteOverride;\n }\n): void;\nexport function parameterize<T extends object, U = Spec | Suite>(\n testType: 'spec' | 'suite',\n testCases: T,\n test: (spec: U, name: keyof T, value: T[keyof T]) => void,\n overrides?: {\n [P in keyof T]?: U extends Spec ? SpecOverride : SuiteOverride;\n }\n): void {\n const testCaseNames = Object.keys(testCases) as (keyof T)[];\n if (overrides) {\n const overrideNames = Object.keys(\n overrides\n ) as (keyof typeof overrides)[];\n if (\n !overrideNames.every(overrideName => testCaseNames.includes(overrideName))\n ) {\n throw new Error(\n 'Parameterized test override names must match test case name'\n );\n }\n if (\n testType === 'spec'\n // eslint-disable-next-line no-restricted-globals\n && !overrideNames.every(overrideName => [fit, xit].includes(overrides[overrideName] as Spec))\n ) {\n throw new Error('Must configure override with one of the jasmine spec functions: fit or xit');\n }\n if (\n testType === 'suite'\n // eslint-disable-next-line no-restricted-globals\n && !overrideNames.every(overrideName => [fdescribe, xdescribe].includes(overrides[overrideName] as Suite))\n ) {\n throw new Error(\n 'Must configure override with one of the jasmine suite functions: fdescribe or xdescribe'\n );\n }\n }\n testCaseNames.forEach(testCaseName => {\n const defaultTest = testType === 'spec' ? it : describe;\n const spec = overrides?.[testCaseName] ?? defaultTest;\n test(spec as U, testCaseName, testCases[testCaseName]);\n });\n}"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="jasmine" />
|
|
2
|
+
export type Fit = typeof fit;
|
|
3
|
+
export type Xit = typeof xit;
|
|
4
|
+
export type It = typeof it;
|
|
5
|
+
/**
|
|
6
|
+
* One of the jasmine spec functions: fit, xit, or it
|
|
7
|
+
*/
|
|
8
|
+
export type Spec = Fit | Xit | It;
|
|
9
|
+
/**
|
|
10
|
+
* One of the jasmine spec functions: fit or xit
|
|
11
|
+
*/
|
|
12
|
+
export type SpecOverride = Fit | Xit;
|
|
13
|
+
export type Fdescribe = typeof fdescribe;
|
|
14
|
+
export type Xdescribe = typeof xdescribe;
|
|
15
|
+
export type Describe = typeof describe;
|
|
16
|
+
/**
|
|
17
|
+
* One of the jasmine spec functions: fit, xit, or it
|
|
18
|
+
*/
|
|
19
|
+
export type Suite = Fdescribe | Xdescribe | Describe;
|
|
20
|
+
/**
|
|
21
|
+
* One of the jasmine spec functions: fit or xit
|
|
22
|
+
*/
|
|
23
|
+
export type SuiteOverride = Fdescribe | Xdescribe;
|
|
24
|
+
export type ObjectFromNamedList<T extends readonly {
|
|
25
|
+
name: string;
|
|
26
|
+
}[]> = {
|
|
27
|
+
[K in T extends readonly {
|
|
28
|
+
name: infer U;
|
|
29
|
+
}[] ? U : never]: T[number];
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["// The following aliases are just to reduce the number\n// of eslint disables in this source file. In normal\n// test code use the globals directly so eslint can\n// guard accidental check-ins of fit, etc.\n// eslint-disable-next-line no-restricted-globals\nexport type Fit = typeof fit;\nexport type Xit = typeof xit;\nexport type It = typeof it;\n/**\n * One of the jasmine spec functions: fit, xit, or it\n */\nexport type Spec = Fit | Xit | It;\n/**\n * One of the jasmine spec functions: fit or xit\n */\nexport type SpecOverride = Fit | Xit;\n\n// eslint-disable-next-line no-restricted-globals\nexport type Fdescribe = typeof fdescribe;\nexport type Xdescribe = typeof xdescribe;\nexport type Describe = typeof describe;\n/**\n * One of the jasmine spec functions: fit, xit, or it\n */\nexport type Suite = Fdescribe | Xdescribe | Describe;\n/**\n * One of the jasmine spec functions: fit or xit\n */\nexport type SuiteOverride = Fdescribe | Xdescribe;\n\nexport type ObjectFromNamedList<T extends readonly { name: string }[]> = {\n [K in T extends readonly { name: infer U }[] ? U : never]: T[number];\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/// <reference types="jasmine" />
|
|
2
|
-
type Fit = typeof fit;
|
|
3
|
-
type Xit = typeof xit;
|
|
4
|
-
type It = typeof it;
|
|
5
|
-
/**
|
|
6
|
-
* One of the jasmine spec functions: fit, xit, or it
|
|
7
|
-
*/
|
|
8
|
-
type Spec = Fit | Xit | It;
|
|
9
|
-
/**
|
|
10
|
-
* One of the jasmine spec functions: fit or xit
|
|
11
|
-
*/
|
|
12
|
-
type SpecOverride = Fit | Xit;
|
|
13
|
-
/**
|
|
14
|
-
* Used to create a parameterized test using an object of test names and arbitrary test values.
|
|
15
|
-
* In the following example:
|
|
16
|
-
* - the test named `catsAndDogs` is focused for debugging
|
|
17
|
-
* - the test named `frogs` is configured to always be disabled
|
|
18
|
-
* - the test named `men` will run normally as it has no override
|
|
19
|
-
* @example
|
|
20
|
-
* const rainTests = {
|
|
21
|
-
* catsAndDogs: 'idiom',
|
|
22
|
-
* frogs: 'idiom',
|
|
23
|
-
* men: 'lyrics'
|
|
24
|
-
* } as const;
|
|
25
|
-
* describe('Different rains', () => {
|
|
26
|
-
* parameterize(rainTests, (spec, name, value) => {
|
|
27
|
-
* spec(`of type ${name} exist`, () => {
|
|
28
|
-
* expect(value).toBeDefined();
|
|
29
|
-
* });
|
|
30
|
-
* }, {
|
|
31
|
-
* catsAndDogs: fit,
|
|
32
|
-
* frogs: xit
|
|
33
|
-
* });
|
|
34
|
-
* });
|
|
35
|
-
*/
|
|
36
|
-
export declare const parameterize: <T extends object>(testCases: T, test: (spec: Spec, name: keyof T, value: T[keyof T]) => void, specOverrides?: { [P in keyof T]?: SpecOverride | undefined; } | undefined) => void;
|
|
37
|
-
type ObjectFromNamedList<T extends readonly {
|
|
38
|
-
name: string;
|
|
39
|
-
}[]> = {
|
|
40
|
-
[K in T extends readonly {
|
|
41
|
-
name: infer U;
|
|
42
|
-
}[] ? U : never]: T[number];
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Used to create a parameterized test using an array of tests with names.
|
|
46
|
-
* In the following example:
|
|
47
|
-
* - the test named `cats-and-dogs` is focused for debugging
|
|
48
|
-
* - the test named `frogs` is configured to always be disabled
|
|
49
|
-
* - the test named `men` will run normally as it has no override
|
|
50
|
-
* @example
|
|
51
|
-
* const rainTests = [
|
|
52
|
-
* { name: 'cats-and-dogs', type: 'idiom' },
|
|
53
|
-
* { name: 'frogs', type: 'idiom'},
|
|
54
|
-
* { name: 'men', type: 'lyrics'}
|
|
55
|
-
* ] as const;
|
|
56
|
-
* describe('Different rains', () => {
|
|
57
|
-
* parameterizeSpec(rainTests, (spec, name, value) => {
|
|
58
|
-
* spec(`of type ${name} exist`, () => {
|
|
59
|
-
* expect(value.type).toBeDefined();
|
|
60
|
-
* });
|
|
61
|
-
* }, {
|
|
62
|
-
* 'cats-and-dogs': fit,
|
|
63
|
-
* frogs: xit
|
|
64
|
-
* });
|
|
65
|
-
* });
|
|
66
|
-
*/
|
|
67
|
-
export declare const parameterizeSpec: <T extends readonly {
|
|
68
|
-
name: string;
|
|
69
|
-
}[]>(list: T, test: (spec: Spec, name: T extends readonly {
|
|
70
|
-
name: infer U;
|
|
71
|
-
}[] ? U : never, value: T[number]) => void, specOverrides?: { [P in keyof ObjectFromNamedList<T>]?: SpecOverride | undefined; } | undefined) => void;
|
|
72
|
-
export {};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Used to create a parameterized test using an object of test names and arbitrary test values.
|
|
3
|
-
* In the following example:
|
|
4
|
-
* - the test named `catsAndDogs` is focused for debugging
|
|
5
|
-
* - the test named `frogs` is configured to always be disabled
|
|
6
|
-
* - the test named `men` will run normally as it has no override
|
|
7
|
-
* @example
|
|
8
|
-
* const rainTests = {
|
|
9
|
-
* catsAndDogs: 'idiom',
|
|
10
|
-
* frogs: 'idiom',
|
|
11
|
-
* men: 'lyrics'
|
|
12
|
-
* } as const;
|
|
13
|
-
* describe('Different rains', () => {
|
|
14
|
-
* parameterize(rainTests, (spec, name, value) => {
|
|
15
|
-
* spec(`of type ${name} exist`, () => {
|
|
16
|
-
* expect(value).toBeDefined();
|
|
17
|
-
* });
|
|
18
|
-
* }, {
|
|
19
|
-
* catsAndDogs: fit,
|
|
20
|
-
* frogs: xit
|
|
21
|
-
* });
|
|
22
|
-
* });
|
|
23
|
-
*/
|
|
24
|
-
export const parameterize = (testCases, test, specOverrides) => {
|
|
25
|
-
const testCaseNames = Object.keys(testCases);
|
|
26
|
-
if (specOverrides) {
|
|
27
|
-
const overrideNames = Object.keys(specOverrides);
|
|
28
|
-
if (!overrideNames.every(overrideName => testCaseNames.includes(overrideName))) {
|
|
29
|
-
throw new Error('Parameterized test override names must match test case name');
|
|
30
|
-
}
|
|
31
|
-
if (
|
|
32
|
-
// eslint-disable-next-line no-restricted-globals
|
|
33
|
-
!overrideNames.every(overrideName => [fit, xit].includes(specOverrides[overrideName]))) {
|
|
34
|
-
throw new Error('Must configure override with one of the jasmine spec functions: fit or xit');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
testCaseNames.forEach(testCaseName => {
|
|
38
|
-
const spec = specOverrides?.[testCaseName] ?? it;
|
|
39
|
-
test(spec, testCaseName, testCases[testCaseName]);
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Used to create a parameterized test using an array of tests with names.
|
|
44
|
-
* In the following example:
|
|
45
|
-
* - the test named `cats-and-dogs` is focused for debugging
|
|
46
|
-
* - the test named `frogs` is configured to always be disabled
|
|
47
|
-
* - the test named `men` will run normally as it has no override
|
|
48
|
-
* @example
|
|
49
|
-
* const rainTests = [
|
|
50
|
-
* { name: 'cats-and-dogs', type: 'idiom' },
|
|
51
|
-
* { name: 'frogs', type: 'idiom'},
|
|
52
|
-
* { name: 'men', type: 'lyrics'}
|
|
53
|
-
* ] as const;
|
|
54
|
-
* describe('Different rains', () => {
|
|
55
|
-
* parameterizeSpec(rainTests, (spec, name, value) => {
|
|
56
|
-
* spec(`of type ${name} exist`, () => {
|
|
57
|
-
* expect(value.type).toBeDefined();
|
|
58
|
-
* });
|
|
59
|
-
* }, {
|
|
60
|
-
* 'cats-and-dogs': fit,
|
|
61
|
-
* frogs: xit
|
|
62
|
-
* });
|
|
63
|
-
* });
|
|
64
|
-
*/
|
|
65
|
-
export const parameterizeSpec = (list, test, specOverrides) => {
|
|
66
|
-
const testCases = list.reduce((result, entry) => {
|
|
67
|
-
if (result[entry.name]) {
|
|
68
|
-
throw new Error(`Duplicate name found in test case list: ${entry.name}. Make sure all test names are unique.`);
|
|
69
|
-
}
|
|
70
|
-
result[entry.name] = entry;
|
|
71
|
-
return result;
|
|
72
|
-
}, {});
|
|
73
|
-
parameterize(testCases, test, specOverrides);
|
|
74
|
-
};
|
|
75
|
-
//# sourceMappingURL=parameterized.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parameterized.js","sourceRoot":"","sources":["../../src/parameterized.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CACxB,SAAY,EACZ,IAA4D,EAC5D,aAEC,EACG,EAAE;IACN,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAgB,CAAC;IAC5D,IAAI,aAAa,EAAE;QACf,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAC7B,aAAa,CACkB,CAAC;QACpC,IACI,CAAC,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,EAC5E;YACE,MAAM,IAAI,KAAK,CACX,6DAA6D,CAChE,CAAC;SACL;QACD;QACI,iDAAiD;QACjD,CAAC,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAE,CAAC,CAAC,EACzF;YACE,MAAM,IAAI,KAAK,CACX,4EAA4E,CAC/E,CAAC;SACL;KACJ;IACD,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACjC,MAAM,IAAI,GAAG,aAAa,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QACjD,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC5B,IAAO,EACP,IAIS,EACT,aAEC,EACG,EAAE;IACN,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CACzB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACd,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;YACpB,MAAM,IAAI,KAAK,CACX,2CAA2C,KAAK,CAAC,IAAI,wCAAwC,CAChG,CAAC;SACL;QACD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC3B,OAAO,MAAM,CAAC;IAClB,CAAC,EACD,EAAE,CACqB,CAAC;IAC5B,YAAY,CAAyB,SAAS,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;AACzE,CAAC,CAAC","sourcesContent":["// The following aliases are just to reduce the number\n// of eslint disables in this source file. In normal\n// test code use the globals directly so eslint can\n// guard accidental check-ins of fit, etc.\n// eslint-disable-next-line no-restricted-globals\ntype Fit = typeof fit;\ntype Xit = typeof xit;\ntype It = typeof it;\n/**\n * One of the jasmine spec functions: fit, xit, or it\n */\ntype Spec = Fit | Xit | It;\n/**\n * One of the jasmine spec functions: fit or xit\n */\ntype SpecOverride = Fit | Xit;\n\n/**\n * Used to create a parameterized test using an object of test names and arbitrary test values.\n * In the following example:\n * - the test named `catsAndDogs` is focused for debugging\n * - the test named `frogs` is configured to always be disabled\n * - the test named `men` will run normally as it has no override\n * @example\n * const rainTests = {\n * catsAndDogs: 'idiom',\n * frogs: 'idiom',\n * men: 'lyrics'\n * } as const;\n * describe('Different rains', () => {\n * parameterize(rainTests, (spec, name, value) => {\n * spec(`of type ${name} exist`, () => {\n * expect(value).toBeDefined();\n * });\n * }, {\n * catsAndDogs: fit,\n * frogs: xit\n * });\n * });\n */\nexport const parameterize = <T extends object>(\n testCases: T,\n test: (spec: Spec, name: keyof T, value: T[keyof T]) => void,\n specOverrides?: {\n [P in keyof T]?: SpecOverride;\n }\n): void => {\n const testCaseNames = Object.keys(testCases) as (keyof T)[];\n if (specOverrides) {\n const overrideNames = Object.keys(\n specOverrides\n ) as (keyof typeof specOverrides)[];\n if (\n !overrideNames.every(overrideName => testCaseNames.includes(overrideName))\n ) {\n throw new Error(\n 'Parameterized test override names must match test case name'\n );\n }\n if (\n // eslint-disable-next-line no-restricted-globals\n !overrideNames.every(overrideName => [fit, xit].includes(specOverrides[overrideName]!))\n ) {\n throw new Error(\n 'Must configure override with one of the jasmine spec functions: fit or xit'\n );\n }\n }\n testCaseNames.forEach(testCaseName => {\n const spec = specOverrides?.[testCaseName] ?? it;\n test(spec, testCaseName, testCases[testCaseName]);\n });\n};\n\ntype ObjectFromNamedList<T extends readonly { name: string }[]> = {\n [K in T extends readonly { name: infer U }[] ? U : never]: T[number];\n};\n\n/**\n * Used to create a parameterized test using an array of tests with names.\n * In the following example:\n * - the test named `cats-and-dogs` is focused for debugging\n * - the test named `frogs` is configured to always be disabled\n * - the test named `men` will run normally as it has no override\n * @example\n * const rainTests = [\n * { name: 'cats-and-dogs', type: 'idiom' },\n * { name: 'frogs', type: 'idiom'},\n * { name: 'men', type: 'lyrics'}\n * ] as const;\n * describe('Different rains', () => {\n * parameterizeSpec(rainTests, (spec, name, value) => {\n * spec(`of type ${name} exist`, () => {\n * expect(value.type).toBeDefined();\n * });\n * }, {\n * 'cats-and-dogs': fit,\n * frogs: xit\n * });\n * });\n */\nexport const parameterizeSpec = <T extends readonly { name: string }[]>(\n list: T,\n test: (\n spec: Spec,\n name: keyof ObjectFromNamedList<T>,\n value: T[number]\n ) => void,\n specOverrides?: {\n [P in keyof ObjectFromNamedList<T>]?: SpecOverride;\n }\n): void => {\n const testCases = list.reduce<{ [key: string]: { name: string } }>(\n (result, entry) => {\n if (result[entry.name]) {\n throw new Error(\n `Duplicate name found in test case list: ${entry.name}. Make sure all test names are unique.`\n );\n }\n result[entry.name] = entry;\n return result;\n },\n {}\n ) as ObjectFromNamedList<T>;\n parameterize<ObjectFromNamedList<T>>(testCases, test, specOverrides);\n};\n"]}
|