Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ jobs:
run: npm test
- name: Build
run: npm run build
- name: Mutation targets
if: github.event_name == 'pull_request'
id: targets
env:
BASE: origin/${{ github.base_ref }}
run: echo "files=$(scripts/mutation-targets.sh "$BASE")" >> "$GITHUB_OUTPUT"
- name: Mutation test the changed logic
if: github.event_name == 'pull_request' && steps.targets.outputs.files != ''
timeout-minutes: 30
env:
FILES: ${{ steps.targets.outputs.files }}
run: |
npm i --no-save @stryker-mutator/core@10.1.1 @stryker-mutator/vitest-runner@10.1.1
npx stryker run --mutate "$FILES"

commitlint:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ node_modules/
.DS_Store
# brainstorm artifacts (not project code)
.superpowers/

.stryker-tmp/
reports/
16 changes: 16 additions & 0 deletions scripts/mutation-targets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Comma-separated logic files a PR must leave without surviving mutants: every changed
# file in src/lib plus the src/lib file behind every changed test. Pages, components,
# data and the client wiring stay out.
set -euo pipefail
base="$1"
# A deleted test counts too: removing it can leave its source with surviving mutants.
git diff --name-only --diff-filter=AMRD "$base"...HEAD -- src tests |
while read -r f; do
case "$f" in
tests/*.test.ts) f="src/lib/$(basename "$f" .test.ts).ts" ;;
esac
[ -f "$f" ] && echo "$f"
done |
grep -E '^src/lib/.*\.ts$' |
sort -u | paste -sd, - || true
16 changes: 16 additions & 0 deletions stryker.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"testRunner": "vitest",
"plugins": ["@stryker-mutator/vitest-runner", "./stryker/noise-ignorer.mjs"],
"ignorers": ["noise"],
"reporters": ["clear-text"],
"clearTextReporter": {
"logTests": false
},
"thresholds": {
"high": 100,
"low": 100,
"break": 100
},
"tsconfigFile": ""
}
41 changes: 41 additions & 0 deletions stryker/noise-ignorer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { declareValuePlugin, PluginKind } from "@stryker-mutator/api/plugin";

const STYLE_ATTRIBUTES = new Set(["className", "style"]);

function isErrorMessage(path) {
const parent = path.parentPath;
return Boolean(
parent?.isNewExpression() &&
parent.node.callee.type === "Identifier" &&
/Error$/.test(parent.node.callee.name) &&
parent.node.arguments.includes(path.node),
);
}

function isAssertionLabel(path) {
const parent = path.parentPath;
if (!parent?.isCallExpression() || !parent.node.arguments.includes(path.node)) return false;
const callee = parent.node.callee;
const name = callee.type === "Identifier" ? callee.name : callee.property?.name;
return typeof name === "string" && /^(assert|require)[A-Z]/.test(name);
}

function isStyleAttribute(path) {
const attr = path.findParent((p) => p.isJSXAttribute());
return Boolean(attr && STYLE_ATTRIBUTES.has(attr.node.name.name));
}

export const strykerPlugins = [
declareValuePlugin(PluginKind.Ignore, "noise", {
shouldIgnore(path) {
if ((path.isStringLiteral() || path.isTemplateLiteral()) && isErrorMessage(path))
return "Error message text is not part of the contract";
if (path.isStringLiteral() && isAssertionLabel(path))
return "Label only used in the assertion error message";
if (path.isJSXAttribute() && STYLE_ATTRIBUTES.has(path.node.name.name))
return "Styling is checked visually, not by unit tests";
if (isStyleAttribute(path)) return "Styling is checked visually, not by unit tests";
return undefined;
},
}),
];
12 changes: 9 additions & 3 deletions tests/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ const p = (name: string, category: string): Project => ({
});

describe("groupByCategory", () => {
it("orders groups by the declared order and preserves item order", () => {
const projects = [p("a", "web apps"), p("b", "flipper zero"), p("c", "web apps")];
it("orders groups by the declared order and projects by name, ignoring case", () => {
const projects = [
p("c", "web apps"),
p("x", "flipper zero"),
p("B", "web apps"),
p("a", "web apps"),
p("b", "web apps"),
];
const groups = groupByCategory(projects, ["web apps", "flipper zero"]);
expect(groups.map((g) => g.category)).toEqual(["web apps", "flipper zero"]);
expect(groups[0].projects.map((x) => x.name)).toEqual(["a", "c"]);
expect(groups[0].projects.map((x) => x.name)).toEqual(["a", "B", "b", "c"]);
});

it("appends categories missing from the order list, sorted alphabetically", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/theme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("nextPref", () => {

describe("isThemePref", () => {
it("accepts valid values and rejects others", () => {
expect(isThemePref("auto")).toBe(true);
expect(["light", "dark", "auto"].every(isThemePref)).toBe(true);
expect(isThemePref("blue")).toBe(false);
expect(isThemePref(null)).toBe(false);
});
Expand Down
Loading