|
1 |
| -import { getColumnDefinitions } from "./columns"; |
| 1 | +import { getColumnDefinition, getColumnSlugs } from "./columns"; |
2 | 2 | import { ColumnValue } from "./glide";
|
3 | 3 |
|
4 |
| -const definitions = getColumnDefinitions(); |
| 4 | +import { execSync } from "child_process"; |
5 | 5 |
|
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); |
8 | 14 |
|
9 | 15 | if (tests.length === 0) return;
|
10 | 16 |
|
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 | + ); |
27 | 34 |
|
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 | + } |
33 | 41 | }
|
34 |
| - } |
35 |
| - }); |
36 |
| - } |
| 42 | + }); |
| 43 | + } |
| 44 | + }); |
37 | 45 | });
|
0 commit comments