Skip to content

Commit

Permalink
Use vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Oct 14, 2024
1 parent f8bf7bb commit bdc9dda
Show file tree
Hide file tree
Showing 9 changed files with 1,265 additions and 602 deletions.
52 changes: 15 additions & 37 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,43 +1,23 @@
import typescriptEslint from '@typescript-eslint/eslint-plugin'
import prettier from 'eslint-plugin-prettier'
import tsParser from '@typescript-eslint/parser'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [
...compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'prettier',
),
export default tseslint.config(
{
ignores: ['esm/**/*', 'dist/**/*', '*.js', '*.mjs', 'example/*'],
},
{
plugins: {
'@typescript-eslint': typescriptEslint,
prettier,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: 'script',

parserOptions: {
project: './tsconfig.lint.json',
project: ['./tsconfig.lint.json'],
tsconfigRootDir: import.meta.dirname,
},
},

},
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylisticTypeChecked,
...tseslint.configs.strictTypeChecked,
{
rules: {
curly: 'error',

Expand All @@ -57,8 +37,6 @@ export default [
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'prettier/prettier': 'error',
},
},
]

)
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@
"node": ">=6"
},
"scripts": {
"test": "jest",
"coverage": "npm test -- --coverage",
"lint": "eslint --report-unused-disable-directives --max-warnings 0 src test",
"test": "vitest",
"lint": "eslint --report-unused-disable-directives --max-warnings 0",
"docs": "documentation readme src/parse.ts --section=API --shallow",
"postdocs": "prettier --write README.md",
"clean": "rimraf dist esm",
"build:esm": "tsc --target es2018 --outDir esm",
"build:es5": "tsc --target es2015 --module commonjs --outDir dist",
"build": "npm run build:esm && npm run build:es5",
"prebuild": "npm run clean && npm run lint",
"preversion": "npm run lint && npm test && npm run build",
"preversion": "npm run lint && npm test --run && npm run build",
"version": "standard-changelog && git add CHANGELOG.md",
"postversion": "git push --follow-tags"
},
Expand All @@ -43,18 +42,21 @@
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.7.0",
"@types/jest": "^29.2.4",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@typescript-eslint/eslint-plugin": "^8.8.1",
"@typescript-eslint/parser": "^8.8.1",
"@vitest/coverage-v8": "2.1.3",
"documentation": "^14.0.1",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^56.0.0",
"jest": "^29.3.1",
"prettier": "^3.2.4",
"rimraf": "^6.0.1",
"standard-changelog": "^6.0.0",
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"typescript-eslint": "^8.8.1"
},
"keywords": [
"vcf",
Expand All @@ -64,5 +66,8 @@
],
"publishConfig": {
"access": "public"
},
"dependencies": {
"vitest": "^2.1.3"
}
}
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ export function parseBreakend(breakendString: string): Breakend | undefined {
Replacement: breakendString.slice(0, breakendString.length - 1),
}
} else if (breakendString.startsWith('<')) {
const res = breakendString.match('<(.*)>(.*)')
const res = /<(.*)>(.*)/.exec(breakendString)
if (!res) {
throw new Error(`failed to parse ${breakendString}`)
}
const Replacement = res?.[2]
const Replacement = res[2]
return Replacement
? {
Join: 'left',
Replacement,
MateDirection: 'right',
MatePosition: `<${res?.[1]}>:1`,
MatePosition: `<${res[1]}>:1`,

Check failure on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test on node 20.x and ubuntu-latest

Invalid type "string | undefined" of template literal expression
}
: undefined
} else if (breakendString.includes('<')) {
const res = breakendString.match('(.*)<(.*)>')
const res = /(.*)<(.*)>/.exec(breakendString)
if (!res) {
throw new Error(`failed to parse ${breakendString}`)
}
const Replacement = res?.[1]
const Replacement = res[1]
return Replacement
? {
Join: 'right',
Replacement,
MateDirection: 'right',
MatePosition: `<${res?.[2]}>:1`,
MatePosition: `<${res[2]}>:1`,

Check failure on line 72 in src/index.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test on node 20.x and ubuntu-latest

Invalid type "string | undefined" of template literal expression
}
: undefined
}
Expand Down
4 changes: 2 additions & 2 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class VCF {
header: string
strict?: boolean
}) {
if (!header?.length) {
if (!header.length) {
throw new Error('empty header received')
}
const headerLines = header.split(/[\r\n]+/).filter(line => line)
Expand Down Expand Up @@ -136,7 +136,7 @@ export default class VCF {
* newlines.
*/
_parseMetadata(line: string) {
const match = line.trim().match(/^##(.+?)=(.*)/)
const match = /^##(.+?)=(.*)/.exec(line.trim())
if (!match) {
throw new Error(`Line is not a valid metadata line: ${line}`)
}
Expand Down
124 changes: 62 additions & 62 deletions test/__snapshots__/parse.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Obscure VCF vcf lines with weird info field and missing format/genotypes 1`] = `
exports[`Obscure VCF > vcf lines with weird info field and missing format/genotypes 1`] = `
[
Variant {
"ALT": [
Expand Down Expand Up @@ -155,7 +155,7 @@ exports[`Obscure VCF vcf lines with weird info field and missing format/genotype
]
`;

exports[`VCF parser can get metadata from the header 1`] = `
exports[`VCF parser > can get metadata from the header 1`] = `
{
"ALT": {
"*": {
Expand Down Expand Up @@ -522,7 +522,7 @@ exports[`VCF parser can get metadata from the header 1`] = `
}
`;

exports[`VCF parser can get metadata from the header 2`] = `
exports[`VCF parser > can get metadata from the header 2`] = `
{
"1000G": {
"Description": "1000 Genomes membership",
Expand Down Expand Up @@ -748,7 +748,7 @@ exports[`VCF parser can get metadata from the header 2`] = `
}
`;

exports[`VCF parser can parse a line from the VCF spec 1`] = `
exports[`VCF parser > can parse a line from the VCF spec 1`] = `
Variant {
"ALT": [
"A",
Expand Down Expand Up @@ -777,7 +777,7 @@ Variant {
}
`;

exports[`VCF parser can parse a line from the VCF spec 2`] = `
exports[`VCF parser > can parse a line from the VCF spec 2`] = `
{
"NA00001": {
"DP": [
Expand Down Expand Up @@ -827,7 +827,7 @@ exports[`VCF parser can parse a line from the VCF spec 2`] = `
}
`;

exports[`VCF parser can parse a line with minimal entries 1`] = `
exports[`VCF parser > can parse a line with minimal entries 1`] = `
Variant {
"ALT": [
"A",
Expand All @@ -842,7 +842,7 @@ Variant {
}
`;

exports[`VCF parser can parse a line with minimal entries 2`] = `
exports[`VCF parser > can parse a line with minimal entries 2`] = `
{
"NA00001": {
"DP": null,
Expand All @@ -865,7 +865,55 @@ exports[`VCF parser can parse a line with minimal entries 2`] = `
}
`;

exports[`VCF parser for Y chrom (haploid) can parse a line from the VCF spec 1`] = `
exports[`VCF parser > parses a line with a breakend ALT 1`] = `
Variant {
"ALT": [
"G]17:198982]",
],
"CHROM": "2",
"FILTER": "PASS",
"ID": [
"bnd_W",
],
"INFO": {
"SVTYPE": [
"BND",
],
},
"POS": 321681,
"QUAL": 6,
"REF": "G",
}
`;

exports[`VCF parser > parses a line with mix of multiple breakends and non breakends 1`] = `
Variant {
"ALT": [
"CTATGTCG",
"C[2 : 321682[",
"C[17 : 198983[",
],
"CHROM": "13",
"FILTER": "PASS",
"ID": [
"bnd_U",
],
"INFO": {
"MATEID": [
"bnd V",
"bnd Z",
],
"SVTYPE": [
"BND",
],
},
"POS": 123456,
"QUAL": 6,
"REF": "C",
}
`;

exports[`VCF parser for Y chrom (haploid) > can parse a line from the VCF spec 1`] = `
Variant {
"ALT": [
"<CN0>",
Expand Down Expand Up @@ -920,7 +968,7 @@ Variant {
}
`;

exports[`VCF parser for Y chrom (haploid) can parse a line from the VCF spec 2`] = `
exports[`VCF parser for Y chrom (haploid) > can parse a line from the VCF spec 2`] = `
{
"HG00096": {
"CN": [
Expand Down Expand Up @@ -1009,7 +1057,7 @@ exports[`VCF parser for Y chrom (haploid) can parse a line from the VCF spec 2`]
}
`;

exports[`VCF parser for Y chrom (haploid) can parse a line from the VCF spec 3`] = `
exports[`VCF parser for Y chrom (haploid) > can parse a line from the VCF spec 3`] = `
Variant {
"ALT": [
"A",
Expand Down Expand Up @@ -1064,7 +1112,7 @@ Variant {
}
`;

exports[`VCF parser for Y chrom (haploid) can parse a line from the VCF spec 4`] = `
exports[`VCF parser for Y chrom (haploid) > can parse a line from the VCF spec 4`] = `
{
"HG00096": {
"GT": [
Expand All @@ -1087,7 +1135,7 @@ exports[`VCF parser for Y chrom (haploid) can parse a line from the VCF spec 4`]
}
`;

exports[`VCF parser for structural variants can parse a line from the VCF spec 1`] = `
exports[`VCF parser for structural variants > can parse a line from the VCF spec 1`] = `
Variant {
"ALT": [
"<DEL>",
Expand Down Expand Up @@ -1151,7 +1199,7 @@ Variant {
}
`;

exports[`VCF parser for structural variants can parse a line from the VCF spec 2`] = `
exports[`VCF parser for structural variants > can parse a line from the VCF spec 2`] = `
{
"/seq/schatz/fritz/sv-paper/real/Nanopore_NA12878/mapped/ngm_Nanopore_human_ngmlr-0.2.3_mapped.bam": {
"DR": [
Expand All @@ -1167,54 +1215,6 @@ exports[`VCF parser for structural variants can parse a line from the VCF spec 2
}
`;

exports[`VCF parser parses a line with a breakend ALT 1`] = `
Variant {
"ALT": [
"G]17:198982]",
],
"CHROM": "2",
"FILTER": "PASS",
"ID": [
"bnd_W",
],
"INFO": {
"SVTYPE": [
"BND",
],
},
"POS": 321681,
"QUAL": 6,
"REF": "G",
}
`;

exports[`VCF parser parses a line with mix of multiple breakends and non breakends 1`] = `
Variant {
"ALT": [
"CTATGTCG",
"C[2 : 321682[",
"C[17 : 198983[",
],
"CHROM": "13",
"FILTER": "PASS",
"ID": [
"bnd_U",
],
"INFO": {
"MATEID": [
"bnd V",
"bnd Z",
],
"SVTYPE": [
"BND",
],
},
"POS": 123456,
"QUAL": 6,
"REF": "C",
}
`;

exports[`can parse breakends 1`] = `
[
Variant {
Expand Down
Loading

0 comments on commit bdc9dda

Please sign in to comment.