-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds threshold parsing from vitest config
- Loading branch information
1 parent
8253128
commit 865faf2
Showing
7 changed files
with
124 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { readFile } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { JsonSummary } from './types/JsonSummary'; | ||
|
||
const parseJsonSummary = async (jsonSummaryPath: string): Promise<JsonSummary> => { | ||
const resolvedJsonSummaryPath = path.resolve(process.cwd(), jsonSummaryPath); | ||
const jsonSummaryRaw = await readFile(resolvedJsonSummaryPath); | ||
return JSON.parse(jsonSummaryRaw.toString()) as JsonSummary; | ||
} | ||
|
||
export { | ||
parseJsonSummary | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import path from 'path'; | ||
import { parseThresholds } from './parseThresholds'; | ||
|
||
// get current dir name in module environment by url | ||
const moduleDir = path.dirname(new URL(import.meta.url).pathname); | ||
|
||
describe('generateTableData', () => { | ||
const mockConfigPath = path.resolve(moduleDir, '..', 'test', 'mockConfig'); | ||
const getConfig = (configName: string) => path.resolve(mockConfigPath, configName) | ||
|
||
it('reads all the thresholds from the given configuration file.', async (): Promise<void> => { | ||
const thresholds = await parseThresholds(getConfig('vitest.config.all.js')); | ||
|
||
expect(thresholds).toEqual({ | ||
lines: 60, | ||
branches: 70, | ||
functions: 80, | ||
statements: 90 | ||
}); | ||
}); | ||
|
||
|
||
it('sets thresholds to 100 if 100 property is true.', async (): Promise<void> => { | ||
const thresholds = await parseThresholds(getConfig('vitest.config.100.js')); | ||
|
||
expect(thresholds).toEqual({ | ||
lines: 100, | ||
branches: 100, | ||
functions: 100, | ||
statements: 100 | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { readFile } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { Thresholds } from './types/Threshold'; | ||
|
||
import { loadConfigFromFile, resolveConfig, } from 'vite'; | ||
|
||
const parseThresholds = async (vitestConfigPath: string): Promise<Thresholds> => { | ||
const resolvedViteConfigPath = path.resolve(process.cwd(), vitestConfigPath); | ||
const configObj = await loadConfigFromFile({command: 'build', mode: 'production' }, resolvedViteConfigPath); | ||
|
||
if(!configObj) { | ||
return {}; | ||
} | ||
|
||
const config = configObj.config; | ||
|
||
if(config.test?.coverage?.["100"]) { | ||
return { | ||
lines: 100, | ||
branches: 100, | ||
functions: 100, | ||
statements: 100, | ||
} | ||
} | ||
|
||
return { | ||
lines: config.test?.coverage?.lines, | ||
branches: config.test?.coverage?.branches, | ||
functions: config.test?.coverage?.functions, | ||
statements: config.test?.coverage?.statements, | ||
} | ||
} | ||
|
||
export { | ||
parseThresholds | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineConfig } from 'vite'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
coverage: { | ||
all: true, | ||
reporter: ['text', 'json-summary'], | ||
include: ['src'], | ||
exclude: ['src/types'], | ||
"100": true | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defineConfig } from 'vite'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
coverage: { | ||
all: true, | ||
reporter: ['text', 'json-summary'], | ||
include: ['src'], | ||
exclude: ['src/types'], | ||
lines: 60, | ||
branches: 70, | ||
functions: 80, | ||
statements: 90 | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { defineConfig } from 'vite'; | ||
|
||
export default defineConfig({ | ||
}); |