Skip to content

Commit e2d6334

Browse files
authored
Only test changed (#70)
1 parent dadaa67 commit e2d6334

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

src/columns.test.ts

+36-28
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
1-
import { getColumnDefinitions } from "./columns";
1+
import { getColumnDefinition, getColumnSlugs } from "./columns";
22
import { ColumnValue } from "./glide";
33

4-
const definitions = getColumnDefinitions();
4+
import { execSync } from "child_process";
55

6-
Object.values(definitions).forEach(definition => {
7-
const { name, tests = [], params: staticParams } = definition;
6+
const changedSlugs = Array.from(
7+
execSync("git diff --name-only HEAD", { encoding: "utf-8" }).matchAll(/src\/columns\/(.+)\.ts/g)
8+
).map(x => x[1]);
9+
10+
const slugsToTest = changedSlugs.length > 0 ? changedSlugs : getColumnSlugs();
11+
12+
slugsToTest.forEach(slug => {
13+
const { run, tests = [], params: staticParams } = getColumnDefinition(slug);
814

915
if (tests.length === 0) return;
1016

11-
for (const { params: testParams, expectedResult, allowFailure } of tests) {
12-
const paramsDescription = Object.entries(testParams)
13-
.map(([k, v]) => `${k}: ${JSON.stringify(v)}`)
14-
.join(", ");
15-
const description = `${name} { ${paramsDescription} } = ${JSON.stringify(expectedResult)}${
16-
allowFailure === true ? " FAILURE EXPECTED" : ""
17-
}`;
18-
test(description, async () => {
19-
try {
20-
const params = Object.entries(staticParams).map(
21-
([name, columnParam]) =>
22-
({
23-
type: columnParam.type,
24-
value: testParams[name],
25-
} as ColumnValue)
26-
);
17+
describe(slug, () => {
18+
for (const { params: testParams, expectedResult, allowFailure } of tests) {
19+
const paramsDescription = Object.entries(testParams)
20+
.map(([k, v]) => `${k}: ${JSON.stringify(v)}`)
21+
.join(", ");
22+
const description = `{ ${paramsDescription} } = ${JSON.stringify(expectedResult)}${
23+
allowFailure === true ? " FAILURE EXPECTED" : ""
24+
}`;
25+
test(description, async () => {
26+
try {
27+
const params = Object.entries(staticParams).map(
28+
([name, columnParam]) =>
29+
({
30+
type: columnParam.type,
31+
value: testParams[name],
32+
} as ColumnValue)
33+
);
2734

28-
const result = await definition.run(...params);
29-
expect(result).toStrictEqual(expectedResult);
30-
} catch (error) {
31-
if (allowFailure !== true) {
32-
throw error;
35+
const result = await run(...params);
36+
expect(result).toStrictEqual(expectedResult);
37+
} catch (error) {
38+
if (allowFailure !== true) {
39+
throw error;
40+
}
3341
}
34-
}
35-
});
36-
}
42+
});
43+
}
44+
});
3745
});

0 commit comments

Comments
 (0)