Guide - Så gör du när du inte vill köra alla tester varje gång
-
Öppna
package.jsonoch lägg till skriptet -
"test:only": "npx --node-options=--experimental-vm-modules jest -t"sist -
bland skripten (glöm inte att lägga till ett kommatecken efter det näst sista
-
skriptet).
{"name": "assignment-a2-descriptive-statistics","version": "1.2.0","description": "1DV025 - Assignment A2 - Descriptive Statistics","type": "module","main": "src/app.js","scripts": {"start": "node src/app.js","lint": "npx eslint ./src || exit 0","lint:fix": "npx eslint ./src --fix || exit 0","test": "npx --node-options=--experimental-vm-modules jest || exit 0","test:only": "npx --node-options=--experimental-vm-modules jest -t"},... -
Spara
package.jsonfilen. -
Kör alla tester med
npm testoch studera resultatet. Konstatera att det -
finns namn specificerade som till exempel average, argument,
-
exceptions. Dessa namn kan användas för att begränsa vilka tester som ska köras.
> assignment-a2-descriptive-statistics@1.2.0 test> npx --node-options=--experimental-vm-modules jest || exit 0(node:32892) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time(Use `node --trace-warnings ...` to show where the warning was created)FAIL test/statistics.test.jsaverageargumentexceptions× passing anything but an array should throw TypeError with the custom message 'The passed argument is not an array.' (6 ms)× passing an empty array should throw Error with the custom message 'The passed array contains no elements.' (2 ms)× passing an array containing a value that is not of the type number should throw TypeError with the custom message 'The passed array may only contain valid numbers.' (2 ms)× passing an array containing the value Number.NaN should throw TypeError with the custom message 'The passed array may only contain valid numbers.' (1 ms)× passing a large array (200000 elements) should not throw an exception (33 ms)side effects× passing [4, 2, 6, 1, 3, 7, 5, 3] should return a value and not modify the argument (1 ms)return value× passing [-2, 5, 1, 1, 5, 5, 2, -2, 2, -2] should return 1.5× passing [-42, -84, -2, -3] should return -32.75... -
För att köra testerna som har med average att göra kör skriptet
test:only -
och skicka med
"average"som ett argument.npm run test:only "average" -
Enbart de tester som återfinns under namnet average kommer att köras.
> assignment-a2-descriptive-statistics@1.2.0 test:only> npx --node-options=--experimental-vm-modules jest -t average(node:31480) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time(Use `node --trace-warnings ...` to show where the warning was created)FAIL test/statistics.test.jsaverageargumentexceptions× passing anything but an array should throw TypeError with the custom message 'The passed argument is not an array.' (4 ms)× passing an empty array should throw Error with the custom message 'The passed array contains no elements.' (1 ms)× passing an array containing a value that is not of the type number should throw TypeError with the custom message 'The passed array may only contain valid numbers.' (1 ms)× passing an array containing the value Number.NaN should throw TypeError with the custom message 'The passed array may only contain valid numbers.' (1 ms)× passing a large array (200000 elements) should not throw an exception (30 ms)side effects× passing [4, 2, 6, 1, 3, 7, 5, 3] should return a value and not modify the argumentreturn value× passing [-2, 5, 1, 1, 5, 5, 2, -2, 2, -2] should return 1.5× passing [-42, -84, -2, -3] should return -32.75maximumargumentexceptions○ skipped passing anything but an array should throw TypeError with the custom message 'The passed argument is not an array.'<OUTPUT OMITTED FOR CLARITY!>Test Suites: 1 failed, 1 totalTests: 10 failed, 60 skipped, 70 totalSnapshots: 0 totalTime: 1.175 sRan all test suites with tests matching "average". -
Vill du istället köra testerna som återfinns under namnet maximum, och
-
hoppa över alla andra, kör du skriptet
test:onlyoch skicka med -
"maximum"som ett argument.npm run test:only "maximum"