1
0
mirror of https://github.com/morris/vanilla-todo.git synced 2025-08-21 13:21:29 +02:00

combine unit and e2e coverage, simplify test scripts

This commit is contained in:
Morris Brodersen
2024-01-29 23:52:14 +01:00
parent 9991ec23b1
commit dd29d07d31
6 changed files with 81 additions and 38 deletions

View File

@@ -570,12 +570,12 @@ just one dependency.
Reference: Reference:
- [addItem.test.mjs](./test/e2e/addItem.test.mjs) - [addItem.test.js](./test/e2e/addItem.test.js)
- [util.test.mjs](./test/unit/util.test.mjs) - [util.test.js](./test/unit/util.test.js)
#### 4.3.1. Code Coverage #### 4.3.1. Code Coverage
I was able to set up code coverage (at least for end-to-end tests) via I was able to set up code coverage for unit _and_ end-to-end tests via
[Playwright's code coverage feature](https://playwright.dev/docs/api/class-coverage) [Playwright's code coverage feature](https://playwright.dev/docs/api/class-coverage)
and [c8](https://github.com/bcoe/c8). This introduced another dependency and was and [c8](https://github.com/bcoe/c8). This introduced another dependency and was
slightly more involved to get right, e.g. mapping localhost URLs to file URLs. slightly more involved to get right, e.g. mapping localhost URLs to file URLs.
@@ -589,7 +589,7 @@ Note that the implementation is specific to the project structure, e.g.
Reference: Reference:
- [test-coverage.sh](./scripts/test-coverage.sh) - [test-coverage.sh](./scripts/test-coverage.sh)
- [coverage.mjs](./test/coverage.mjs) - [coverage.js](./test/coverage.js)
### 4.4. Pipeline ### 4.4. Pipeline
@@ -880,6 +880,11 @@ Thanks!
## 9. Changelog ## 9. Changelog
### 01/2024
- Correctly combine [code coverage](#431-code-coverage) from end-to-end and unit
tests
### 12/2023 ### 12/2023
- Added [debugging section](#45-debugging) - Added [debugging section](#45-debugging)

52
package-lock.json generated
View File

@@ -10,7 +10,7 @@
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@playwright/test": "^1.33.0", "@playwright/test": "^1.33.0",
"c8": "^8.0.1", "c8": "^9.1.0",
"eslint": "^8.20.0", "eslint": "^8.20.0",
"eslint-plugin-compat": "^4.0.2", "eslint-plugin-compat": "^4.0.2",
"mime": "^4.0.0", "mime": "^4.0.0",
@@ -670,19 +670,18 @@
} }
}, },
"node_modules/c8": { "node_modules/c8": {
"version": "8.0.1", "version": "9.1.0",
"resolved": "https://registry.npmjs.org/c8/-/c8-8.0.1.tgz", "resolved": "https://registry.npmjs.org/c8/-/c8-9.1.0.tgz",
"integrity": "sha512-EINpopxZNH1mETuI0DzRA4MZpAUH+IFiRhnmFD3vFr3vdrgxqi3VfE3KL0AIL+zDq8rC9bZqwM/VDmmoe04y7w==", "integrity": "sha512-mBWcT5iqNir1zIkzSPyI3NCR9EZCVI3WUD+AVO17MVWTSFNyUueXE82qTeampNtTr+ilN/5Ua3j24LgbCKjDVg==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@bcoe/v8-coverage": "^0.2.3", "@bcoe/v8-coverage": "^0.2.3",
"@istanbuljs/schema": "^0.1.3", "@istanbuljs/schema": "^0.1.3",
"find-up": "^5.0.0", "find-up": "^5.0.0",
"foreground-child": "^2.0.0", "foreground-child": "^3.1.1",
"istanbul-lib-coverage": "^3.2.0", "istanbul-lib-coverage": "^3.2.0",
"istanbul-lib-report": "^3.0.1", "istanbul-lib-report": "^3.0.1",
"istanbul-reports": "^3.1.6", "istanbul-reports": "^3.1.6",
"rimraf": "^3.0.2",
"test-exclude": "^6.0.0", "test-exclude": "^6.0.0",
"v8-to-istanbul": "^9.0.0", "v8-to-istanbul": "^9.0.0",
"yargs": "^17.7.2", "yargs": "^17.7.2",
@@ -692,7 +691,7 @@
"c8": "bin/c8.js" "c8": "bin/c8.js"
}, },
"engines": { "engines": {
"node": ">=12" "node": ">=14.14.0"
} }
}, },
"node_modules/callsites": { "node_modules/callsites": {
@@ -1336,16 +1335,19 @@
"dev": true "dev": true
}, },
"node_modules/foreground-child": { "node_modules/foreground-child": {
"version": "2.0.0", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz",
"integrity": "sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==", "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"cross-spawn": "^7.0.0", "cross-spawn": "^7.0.0",
"signal-exit": "^3.0.2" "signal-exit": "^4.0.1"
}, },
"engines": { "engines": {
"node": ">=8.0.0" "node": ">=14"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/fs.realpath": { "node_modules/fs.realpath": {
@@ -2615,10 +2617,16 @@
} }
}, },
"node_modules/signal-exit": { "node_modules/signal-exit": {
"version": "3.0.7", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",
"dev": true "dev": true,
"engines": {
"node": ">=14"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
}, },
"node_modules/slash": { "node_modules/slash": {
"version": "3.0.0", "version": "3.0.0",
@@ -3142,18 +3150,6 @@
"node": "^14.17.0 || ^16.13.0 || >=18.0.0" "node": "^14.17.0 || ^16.13.0 || >=18.0.0"
} }
}, },
"node_modules/write-file-atomic/node_modules/signal-exit": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
"integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",
"dev": true,
"engines": {
"node": ">=14"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/ws": { "node_modules/ws": {
"version": "8.16.0", "version": "8.16.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz",

View File

@@ -34,7 +34,7 @@
}, },
"devDependencies": { "devDependencies": {
"@playwright/test": "^1.33.0", "@playwright/test": "^1.33.0",
"c8": "^8.0.1", "c8": "^9.1.0",
"eslint": "^8.20.0", "eslint": "^8.20.0",
"eslint-plugin-compat": "^4.0.2", "eslint-plugin-compat": "^4.0.2",
"mime": "^4.0.0", "mime": "^4.0.0",

View File

@@ -1,4 +1,3 @@
set -e set -e
rm -rf coverage rm -rf coverage
COVERAGE=true playwright test $1 c8 --src public --reporter text --reporter lcov playwright test $1
c8 report --src public --reporter text --reporter lcov

View File

@@ -5,7 +5,7 @@ import { test } from 'playwright/test';
// See also https://playwright.dev/docs/api/class-coverage // See also https://playwright.dev/docs/api/class-coverage
if (process.env.COVERAGE) { if (process.env.NODE_V8_COVERAGE) {
test.beforeEach(async ({ page }) => { test.beforeEach(async ({ page }) => {
await page.coverage.startJSCoverage(); await page.coverage.startJSCoverage();
}); });
@@ -20,9 +20,9 @@ if (process.env.COVERAGE) {
})), })),
}; };
await fs.mkdir('coverage/tmp', { recursive: true }); await fs.mkdir(process.env.NODE_V8_COVERAGE, { recursive: true });
await fs.writeFile( await fs.writeFile(
`coverage/tmp/coverage-${randomUUID()}.json`, path.join(process.env.NODE_V8_COVERAGE, `coverage-${randomUUID()}.json`),
JSON.stringify(output), JSON.stringify(output),
); );
}); });

View File

@@ -139,3 +139,46 @@ test('TodoLogic.moveTodoItem', () => {
}, },
]); ]);
}); });
test('TodoLogic.checkTodoItem', () => {
let data = TodoLogic.initTodoData(new Date(0));
data = {
...data,
items: [
{
id: 'a',
listId: '1970-01-01',
label: 'foo',
index: 0,
done: false,
},
{
id: 'b',
listId: '1970-01-01',
label: 'bar',
index: 1,
done: false,
},
],
};
data = TodoLogic.checkTodoItem(data, { id: 'a', done: true });
expect(data.items).toEqual([
{
id: 'a',
listId: '1970-01-01',
label: 'foo',
index: 0,
done: true,
},
{
id: 'b',
listId: '1970-01-01',
label: 'bar',
index: 1,
done: false,
},
]);
});