@ni/jasmine-parameterized 0.3.0 → 1.0.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
CHANGED
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
The `@ni/jasmine-parameterized` library provides utility functions for writing [Jasmine](https://jasmine.github.io/) parameterized tests.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Getting Started
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Install in your app's `devDependencies`:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
2. Use `parameterizeSpec` to write strictly-typed jasmine tests that run for different test scenarios, where each test can be focused or excluded as needed by name.
|
|
9
|
+
```
|
|
10
|
+
npm install -D @ni/jasmine-parameterized
|
|
11
|
+
```
|
|
14
12
|
|
|
15
|
-
### `parameterizeSpec`
|
|
13
|
+
### Using `parameterizeSpec`
|
|
16
14
|
|
|
17
15
|
Use `parameterizeSpec` to create a parameterized test using an array of tests with names.
|
|
18
16
|
|
|
@@ -41,7 +39,7 @@ describe('Different rains', () => {
|
|
|
41
39
|
});
|
|
42
40
|
```
|
|
43
41
|
|
|
44
|
-
### `parameterizeSuite`
|
|
42
|
+
### Using `parameterizeSuite`
|
|
45
43
|
|
|
46
44
|
Use `parameterizeSuite` to create a parameterized test suite using an array of test scenarios with names.
|
|
47
45
|
|
|
@@ -74,3 +72,7 @@ parameterizeSuite(rainTests, (suite, name, value) => {
|
|
|
74
72
|
frogs: xdescribe
|
|
75
73
|
});
|
|
76
74
|
```
|
|
75
|
+
|
|
76
|
+
## Contributing
|
|
77
|
+
|
|
78
|
+
See `Getting Started` in [`CONTRIBUTING.md`](/packages/jasmine-parameterized/CONTRIBUTING.md#getting-started).
|
|
@@ -24,6 +24,4 @@ import { ObjectFromNamedList, Spec, SpecOverride } from './types.js';
|
|
|
24
24
|
*/
|
|
25
25
|
export declare const parameterizeSpec: <T extends readonly {
|
|
26
26
|
name: string;
|
|
27
|
-
}[]>(list: T, test: (spec: Spec, name: T
|
|
28
|
-
name: infer U;
|
|
29
|
-
}[] ? U : never, value: T[number]) => void, specOverrides?: { [P in keyof ObjectFromNamedList<T>]?: SpecOverride | undefined; } | undefined) => void;
|
|
27
|
+
}[]>(list: T, test: (spec: Spec, name: keyof ObjectFromNamedList<T>, value: T[number]) => void, specOverrides?: { [P in keyof ObjectFromNamedList<T>]?: SpecOverride | undefined; } | undefined) => void;
|
|
@@ -1 +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;
|
|
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,CAAC;YACrB,MAAM,IAAI,KAAK,CACX,2CAA2C,KAAK,CAAC,IAAI,wCAAwC,CAChG,CAAC;QACN,CAAC;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"]}
|
|
@@ -29,6 +29,4 @@ import { ObjectFromNamedList, Suite, SuiteOverride } from './types.js';
|
|
|
29
29
|
*/
|
|
30
30
|
export declare const parameterizeSuite: <T extends readonly {
|
|
31
31
|
name: string;
|
|
32
|
-
}[]>(list: T, test: (suite: Suite, name: T
|
|
33
|
-
name: infer U;
|
|
34
|
-
}[] ? U : never, value: T[number]) => void, specOverrides?: { [P in keyof ObjectFromNamedList<T>]?: SuiteOverride | undefined; } | undefined) => void;
|
|
32
|
+
}[]>(list: T, test: (suite: Suite, name: keyof ObjectFromNamedList<T>, value: T[number]) => void, specOverrides?: { [P in keyof ObjectFromNamedList<T>]?: SuiteOverride | undefined; } | undefined) => void;
|
|
@@ -1 +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;
|
|
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,CAAC;YACrB,MAAM,IAAI,KAAK,CACX,4CAA4C,KAAK,CAAC,IAAI,8CAA8C,CACvG,CAAC;QACN,CAAC;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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameterize.js","sourceRoot":"","sources":["../../src/parameterize.ts"],"names":[],"mappings":"AAyCA,MAAM,UAAU,YAAY,CACxB,QAA0B,EAC1B,SAAY,EACZ,IAAyD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M,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}"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ni/jasmine-parameterized",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A utility to write parameterized jasmine tests",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jasmine",
|
|
@@ -42,8 +42,7 @@
|
|
|
42
42
|
"author": "National Instruments",
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@ni/eslint-config-
|
|
46
|
-
"@ni/eslint-config-typescript": "^4.2.0",
|
|
45
|
+
"@ni-private/eslint-config-nimble": "*",
|
|
47
46
|
"@types/jasmine": "^5.1.4",
|
|
48
47
|
"jasmine": "^5.1.0",
|
|
49
48
|
"jasmine-core": "^5.1.2",
|
|
@@ -51,7 +50,7 @@
|
|
|
51
50
|
"karma-jasmine": "^5.1.0",
|
|
52
51
|
"karma-jasmine-html-reporter": "^2.0.0",
|
|
53
52
|
"karma-spec-reporter": "^0.0.36",
|
|
54
|
-
"playwright": "1.
|
|
55
|
-
"typescript": "~5.
|
|
53
|
+
"playwright": "1.44.0",
|
|
54
|
+
"typescript": "~5.4.5"
|
|
56
55
|
}
|
|
57
56
|
}
|