Update vitest (#2475)
* Update vitest * Update vite test config * Fix coverage metrics and bump coverage
This commit is contained in:
2496
package-lock.json
generated
2496
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -73,8 +73,8 @@
|
|||||||
"@types/xml": "^1.0.8",
|
"@types/xml": "^1.0.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.9.1",
|
"@typescript-eslint/eslint-plugin": "^6.9.1",
|
||||||
"@typescript-eslint/parser": "^6.9.1",
|
"@typescript-eslint/parser": "^6.9.1",
|
||||||
"@vitest/coverage-v8": "^0.34.6",
|
"@vitest/coverage-v8": "^1.1.0",
|
||||||
"@vitest/ui": "^0.34.7",
|
"@vitest/ui": "^1.1.0",
|
||||||
"cspell": "^7.3.8",
|
"cspell": "^7.3.8",
|
||||||
"docsify-cli": "^4.3.0",
|
"docsify-cli": "^4.3.0",
|
||||||
"eslint": "^8.23.0",
|
"eslint": "^8.23.0",
|
||||||
@ -99,7 +99,7 @@
|
|||||||
"vite-plugin-dts": "^3.3.1",
|
"vite-plugin-dts": "^3.3.1",
|
||||||
"vite-plugin-node-polyfills": "^0.9.0",
|
"vite-plugin-node-polyfills": "^0.9.0",
|
||||||
"vite-tsconfig-paths": "^4.2.0",
|
"vite-tsconfig-paths": "^4.2.0",
|
||||||
"vitest": "^0.33.0"
|
"vitest": "^1.1.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// http://officeopenxml.com/WPsectionLineNumbering.php
|
// http://officeopenxml.com/WPsectionLineNumbering.php
|
||||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||||
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||||
|
|
||||||
// <xsd:simpleType name="ST_LineNumberRestart">
|
// <xsd:simpleType name="ST_LineNumberRestart">
|
||||||
@ -25,31 +25,23 @@ export const LineNumberRestartFormat = {
|
|||||||
// <xsd:attribute name="restart" type="ST_LineNumberRestart" use="optional" default="newPage"/>
|
// <xsd:attribute name="restart" type="ST_LineNumberRestart" use="optional" default="newPage"/>
|
||||||
// </xsd:complexType>
|
// </xsd:complexType>
|
||||||
|
|
||||||
export interface ILineNumberAttributes {
|
export type ILineNumberAttributes = {
|
||||||
readonly countBy?: number;
|
readonly countBy?: number;
|
||||||
readonly start?: number;
|
readonly start?: number;
|
||||||
readonly restart?: (typeof LineNumberRestartFormat)[keyof typeof LineNumberRestartFormat];
|
readonly restart?: (typeof LineNumberRestartFormat)[keyof typeof LineNumberRestartFormat];
|
||||||
readonly distance?: number | PositiveUniversalMeasure;
|
readonly distance?: number | PositiveUniversalMeasure;
|
||||||
}
|
};
|
||||||
|
|
||||||
export class LineNumberType extends XmlComponent {
|
export const createLineNumberType = ({ countBy, start, restart, distance }: ILineNumberAttributes): XmlComponent =>
|
||||||
public constructor({ countBy, start, restart, distance }: ILineNumberAttributes) {
|
new BuilderElement<ILineNumberAttributes>({
|
||||||
super("w:lnNumType");
|
name: "w:lnNumType",
|
||||||
this.root.push(
|
attributes: {
|
||||||
new NextAttributeComponent<{
|
countBy: { key: "w:countBy", value: countBy === undefined ? undefined : decimalNumber(countBy) },
|
||||||
readonly countBy?: number;
|
start: { key: "w:start", value: start === undefined ? undefined : decimalNumber(start) },
|
||||||
readonly start?: number;
|
restart: { key: "w:restart", value: restart },
|
||||||
readonly restart?: (typeof LineNumberRestartFormat)[keyof typeof LineNumberRestartFormat];
|
distance: {
|
||||||
readonly distance?: number | PositiveUniversalMeasure;
|
key: "w:distance",
|
||||||
}>({
|
value: distance === undefined ? undefined : twipsMeasureValue(distance),
|
||||||
countBy: { key: "w:countBy", value: countBy === undefined ? undefined : decimalNumber(countBy) },
|
},
|
||||||
start: { key: "w:start", value: start === undefined ? undefined : decimalNumber(start) },
|
},
|
||||||
restart: { key: "w:restart", value: restart },
|
});
|
||||||
distance: {
|
|
||||||
key: "w:distance",
|
|
||||||
value: distance === undefined ? undefined : twipsMeasureValue(distance),
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -9,7 +9,7 @@ import { OnOffElement, XmlComponent } from "@file/xml-components";
|
|||||||
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference";
|
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference";
|
||||||
import { Columns, IColumnsAttributes } from "./properties/columns";
|
import { Columns, IColumnsAttributes } from "./properties/columns";
|
||||||
import { DocumentGrid, IDocGridAttributesProperties } from "./properties/doc-grid";
|
import { DocumentGrid, IDocGridAttributesProperties } from "./properties/doc-grid";
|
||||||
import { ILineNumberAttributes, LineNumberType } from "./properties/line-number";
|
import { ILineNumberAttributes, createLineNumberType } from "./properties/line-number";
|
||||||
import { IPageBordersOptions, PageBorders } from "./properties/page-borders";
|
import { IPageBordersOptions, PageBorders } from "./properties/page-borders";
|
||||||
import { IPageMarginAttributes, PageMargin } from "./properties/page-margin";
|
import { IPageMarginAttributes, PageMargin } from "./properties/page-margin";
|
||||||
import { IPageNumberTypeAttributes, PageNumberType } from "./properties/page-number";
|
import { IPageNumberTypeAttributes, PageNumberType } from "./properties/page-number";
|
||||||
@ -137,7 +137,7 @@ export class SectionProperties extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lineNumbers) {
|
if (lineNumbers) {
|
||||||
this.root.push(new LineNumberType(lineNumbers));
|
this.root.push(createLineNumberType(lineNumbers));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.root.push(new PageNumberType(pageNumbers));
|
this.root.push(new PageNumberType(pageNumbers));
|
||||||
|
@ -2,7 +2,7 @@ import { SpaceType } from "@file/shared";
|
|||||||
import { XmlComponent } from "@file/xml-components";
|
import { XmlComponent } from "@file/xml-components";
|
||||||
|
|
||||||
import { TextAttributes } from "../run/text-attributes";
|
import { TextAttributes } from "../run/text-attributes";
|
||||||
import { IPageReferenceOptions } from "./pageref-properties";
|
import { IPageReferenceOptions } from "./pageref";
|
||||||
|
|
||||||
export class PageReferenceFieldInstruction extends XmlComponent {
|
export class PageReferenceFieldInstruction extends XmlComponent {
|
||||||
public constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
public constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
// Options according to https://www.ecma-international.org/publications/standards/Ecma-376.htm (at Part 1, Page 1234)
|
|
||||||
|
|
||||||
export interface IPageReferenceOptions {
|
|
||||||
/**
|
|
||||||
* \h option - Creates a hyperlink to the bookmarked paragraph.
|
|
||||||
*/
|
|
||||||
readonly hyperlink?: boolean;
|
|
||||||
/**
|
|
||||||
* \p option - Causes the field to display its position relative to the source
|
|
||||||
* bookmark. If the PAGEREF field is on the same page as the
|
|
||||||
* bookmark, it omits "on page #" and returns "above" or "below"
|
|
||||||
* only. If the PAGEREF field is not on the same page as the
|
|
||||||
* bookmark, the string "on page #" is used.
|
|
||||||
*/
|
|
||||||
readonly useRelativePosition?: boolean;
|
|
||||||
}
|
|
@ -2,7 +2,22 @@
|
|||||||
import { Begin, End } from "@file/paragraph/run/field";
|
import { Begin, End } from "@file/paragraph/run/field";
|
||||||
import { Run } from "../run";
|
import { Run } from "../run";
|
||||||
import { PageReferenceFieldInstruction } from "./pageref-field-instruction";
|
import { PageReferenceFieldInstruction } from "./pageref-field-instruction";
|
||||||
import type { IPageReferenceOptions } from "./pageref-properties";
|
|
||||||
|
// Options according to https://www.ecma-international.org/publications/standards/Ecma-376.htm (at Part 1, Page 1234)
|
||||||
|
export type IPageReferenceOptions = {
|
||||||
|
/**
|
||||||
|
* \h option - Creates a hyperlink to the bookmarked paragraph.
|
||||||
|
*/
|
||||||
|
readonly hyperlink?: boolean;
|
||||||
|
/**
|
||||||
|
* \p option - Causes the field to display its position relative to the source
|
||||||
|
* bookmark. If the PAGEREF field is on the same page as the
|
||||||
|
* bookmark, it omits "on page #" and returns "above" or "below"
|
||||||
|
* only. If the PAGEREF field is not on the same page as the
|
||||||
|
* bookmark, the string "on page #" is used.
|
||||||
|
*/
|
||||||
|
readonly useRelativePosition?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export class PageReference extends Run {
|
export class PageReference extends Run {
|
||||||
public constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
public constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
||||||
|
@ -65,6 +65,8 @@ export class ImageRun extends Run {
|
|||||||
.map((c) => c.charCodeAt(0)),
|
.map((c) => c.charCodeAt(0)),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
/* c8 ignore next 4 */
|
||||||
|
// Not possible to test this branch in NodeJS
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
||||||
const b = require("buf" + "fer");
|
const b = require("buf" + "fer");
|
||||||
return new b.Buffer(dataURI, "base64");
|
return new b.Buffer(dataURI, "base64");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { defineConfig } from "vitest/config";
|
import { configDefaults, defineConfig } from "vitest/config";
|
||||||
import { resolve } from "path";
|
import { resolve } from "path";
|
||||||
import tsconfigPaths from "vite-tsconfig-paths";
|
import tsconfigPaths from "vite-tsconfig-paths";
|
||||||
import dts from "vite-plugin-dts";
|
import dts from "vite-plugin-dts";
|
||||||
@ -60,10 +60,31 @@ export default defineConfig({
|
|||||||
coverage: {
|
coverage: {
|
||||||
provider: "v8",
|
provider: "v8",
|
||||||
reporter: ["text", "json", "html"],
|
reporter: ["text", "json", "html"],
|
||||||
statements: 99.93,
|
thresholds: {
|
||||||
branches: 98.85,
|
statements: 99.96,
|
||||||
functions: 100,
|
branches: 98.98,
|
||||||
lines: 99.93,
|
functions: 100,
|
||||||
|
lines: 99.96,
|
||||||
|
},
|
||||||
|
exclude: [
|
||||||
|
...configDefaults.exclude,
|
||||||
|
'**/build/**',
|
||||||
|
'**/demo/**',
|
||||||
|
'**/docs/**',
|
||||||
|
'**/scripts/**',
|
||||||
|
'**/src/**/index.ts',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
|
include: [
|
||||||
|
'**/src/**/*.spec.ts',
|
||||||
|
'**/packages/**/*.spec.ts'
|
||||||
|
],
|
||||||
|
exclude: [
|
||||||
|
...configDefaults.exclude,
|
||||||
|
'**/build/**',
|
||||||
|
'**/demo/**',
|
||||||
|
'**/docs/**',
|
||||||
|
'**/scripts/**'
|
||||||
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user