Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ jobs:
- name: Run unit tests
run: pnpm test

- name: Run slow tests
run: pnpm test:slow

run-e2e-tests:
runs-on: ubuntu-latest
container:
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"packageManager": "pnpm@10.25.0",
"scripts": {
"test": "vitest run",
"test:bench": "VITEST_BENCH=true vitest run",
"test:slow": "vitest run --root ./packages/super-editor src/tests/editor/node-import-timing.test.js",
"test:debug": "pnpm --prefix packages/super-editor run test:debug",
"test:inspect": "NODE_OPTIONS=\"--inspect-brk=9229\" vitest --pool threads --poolOptions.threads.singleThread",
"test:all": "vitest run",
Expand Down Expand Up @@ -73,6 +75,7 @@
"eslint-import-resolver-typescript": "catalog:",
"eslint-plugin-import-x": "catalog:",
"eslint-plugin-jsdoc": "catalog:",
"happy-dom": "catalog:",
"husky": "catalog:",
"jsdom": "catalog:",
"lint-staged": "catalog:",
Expand Down
3 changes: 2 additions & 1 deletion packages/layout-engine/contracts/vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import baseConfig from '../../../vitest.baseConfig';
export default defineConfig({
...baseConfig,
test: {
environment: 'jsdom',
// Use happy-dom for faster tests (set VITEST_DOM=jsdom to use jsdom)
environment: process.env.VITEST_DOM || 'happy-dom',
include: ['src/**/*.test.ts']
}
});
5 changes: 4 additions & 1 deletion packages/layout-engine/layout-bridge/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { defineConfig } from 'vitest/config';
import baseConfig from '../../../vitest.baseConfig';

const includeBench = process.env.VITEST_BENCH === 'true';

export default defineConfig({
...baseConfig,
test: {
environment: 'node',
include: ['test/**/*.test.ts'],
include: includeBench ? ['test/**/performance*.test.ts'] : ['test/**/*.test.ts'],
exclude: includeBench ? [] : ['test/**/performance*.test.ts'],
globals: true,
},
});
3 changes: 2 additions & 1 deletion packages/layout-engine/measuring/dom/vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import baseConfig from '../../../../vitest.baseConfig';
export default defineConfig({
...baseConfig,
test: {
environment: 'jsdom',
// Use happy-dom for faster tests (set VITEST_DOM=jsdom to use jsdom)
environment: process.env.VITEST_DOM || 'happy-dom',
include: ['src/**/*.test.ts'],
setupFiles: ['./vitest.setup.ts'],
},
Expand Down
3 changes: 2 additions & 1 deletion packages/layout-engine/painters/dom/vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import baseConfig from '../../../../vitest.baseConfig';
export default defineConfig({
...baseConfig,
test: {
environment: 'jsdom',
// Use happy-dom for faster tests (set VITEST_DOM=jsdom to use jsdom)
environment: process.env.VITEST_DOM || 'happy-dom',
include: ['src/**/*.test.ts'],
},
});
4 changes: 3 additions & 1 deletion packages/layout-engine/pm-adapter/src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ describe('PM → FlowBlock → Measure integration', () => {
const fragment = mount.querySelector('.superdoc-fragment') as HTMLElement;
const shadingLayer = fragment.querySelector('.superdoc-paragraph-shading') as HTMLElement;
expect(shadingLayer).toBeTruthy();
expect(shadingLayer.style.backgroundColor).toBe('rgb(170, 187, 204)');
// Accept both rgb and hex formats (jsdom uses rgb, happy-dom uses hex)
const bgColor = shadingLayer.style.backgroundColor.toLowerCase();
expect(bgColor === 'rgb(170, 187, 204)' || bgColor === '#aabbcc').toBe(true);

document.body.removeChild(mount);
});
Expand Down
3 changes: 2 additions & 1 deletion packages/layout-engine/pm-adapter/vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import baseConfig from '../../../vitest.baseConfig';
export default defineConfig({
...baseConfig,
test: {
environment: 'jsdom',
// Use happy-dom for faster tests (set VITEST_DOM=jsdom to use jsdom)
environment: process.env.VITEST_DOM || 'happy-dom',
include: ['src/**/*.test.ts'],
setupFiles: [resolve(__dirname, './vitest.setup.ts')],
},
Expand Down
10 changes: 8 additions & 2 deletions packages/layout-engine/tests/vitest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { defineConfig } from 'vitest/config';
import baseConfig from '../../../vitest.baseConfig';

const includeBench = process.env.VITEST_BENCH === 'true';

export default defineConfig({
...baseConfig,
test: {
environment: 'jsdom',
include: ['src/**/*.test.ts', 'src/**/*.bench.ts'],
// Use happy-dom for faster tests (set VITEST_DOM=jsdom to use jsdom)
environment: process.env.VITEST_DOM || 'happy-dom',
include: includeBench
? ['src/**/*.bench.ts']
: ['src/**/*.test.ts'],
exclude: includeBench ? [] : ['src/**/*.bench.ts'],
setupFiles: ['./vitest.setup.ts'],
coverage: {
enabled: false,
Expand Down
24 changes: 19 additions & 5 deletions packages/super-editor/src/core/commands/insertContent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ describe('insertContent', () => {
// Integration-style tests that use a real Editor instance to
// insert markdown/HTML lists and verify exported OOXML has list numbering.
describe('insertContent (integration) list export', () => {
// Cache loaded DOCX data and helpers to avoid repeated file loading
let cachedDocxData = null;
let helpers = null;
let exportHelpers = null;

const getListParagraphs = (result) => {
const body = result.elements?.find((el) => el.name === 'w:body');
const paragraphs = (body?.elements || []).filter((el) => el.name === 'w:p');
Expand All @@ -189,16 +194,25 @@ describe('insertContent (integration) list export', () => {
vi.resetModules();
vi.doUnmock('../helpers/contentProcessor.js');

const { loadTestDataForEditorTests, initTestEditor } = await import('../../tests/helpers/helpers.js');
const { docx, media, mediaFiles, fonts } = await loadTestDataForEditorTests('blank-doc.docx');
const { editor } = initTestEditor({ content: docx, media, mediaFiles, fonts, mode: 'docx' });
// Cache helpers and DOCX data on first call
if (!helpers) {
helpers = await import('../../tests/helpers/helpers.js');
}
if (!cachedDocxData) {
cachedDocxData = await helpers.loadTestDataForEditorTests('blank-doc.docx');
}
if (!exportHelpers) {
exportHelpers = await import('../../tests/export/export-helpers/index.js');
}

const { docx, media, mediaFiles, fonts } = cachedDocxData;
const { editor } = helpers.initTestEditor({ content: docx, media, mediaFiles, fonts, mode: 'docx' });
return editor;
};

const exportFromEditorContent = async (editor) => {
const { getExportedResultWithDocContent } = await import('../../tests/export/export-helpers/index.js');
const content = editor.getJSON().content || [];
return await getExportedResultWithDocContent(content);
return await exportHelpers.getExportedResultWithDocContent(content);
};

it('exports ordered list from markdown with numId/ilvl', async () => {
Expand Down
16 changes: 13 additions & 3 deletions packages/super-editor/src/extensions/table/table.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { describe, it, expect, beforeAll, beforeEach, afterEach } from 'vitest';
import { EditorState } from 'prosemirror-state';
import { loadTestDataForEditorTests, initTestEditor } from '@tests/helpers/helpers.js';
import { createTable } from './tableHelpers/createTable.js';
import { promises as fs } from 'fs';

// Cache DOCX data to avoid repeated file loading
let cachedBlankDoc = null;
let cachedBordersDoc = null;

/**
* Find the first table position within the provided document.
* @param {import('prosemirror-model').Node} doc
Expand All @@ -29,8 +33,14 @@ describe('Table commands', async () => {
let templateBlockAttrs;
let table;

// Load DOCX data once before all tests
beforeAll(async () => {
cachedBlankDoc = await loadTestDataForEditorTests('blank-doc.docx');
cachedBordersDoc = await loadTestDataForEditorTests('SD-978-remove-table-borders.docx');
});

const setupTestTable = async () => {
let { docx, media, mediaFiles, fonts } = await loadTestDataForEditorTests('blank-doc.docx');
const { docx, media, mediaFiles, fonts } = cachedBlankDoc;
({ editor } = initTestEditor({ content: docx, media, mediaFiles, fonts }));
({ schema } = editor);

Expand Down Expand Up @@ -600,7 +610,7 @@ describe('Table commands', async () => {

describe('table imported from docx', async () => {
beforeEach(async () => {
let { docx, media, mediaFiles, fonts } = await loadTestDataForEditorTests('SD-978-remove-table-borders.docx');
const { docx, media, mediaFiles, fonts } = cachedBordersDoc;
({ editor } = initTestEditor({ content: docx, media, mediaFiles, fonts }));

tablePos = findTablePos(editor.state.doc);
Expand Down
1 change: 1 addition & 0 deletions packages/super-editor/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default defineConfig(({ mode }) => {
exclude: [
...configDefaults.exclude,
'**/*.spec.js',
'**/node-import-timing.test.js', // Slow test, run separately with test:slow
],
coverage: {
provider: 'v8',
Expand Down
3 changes: 2 additions & 1 deletion packages/superdoc/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export default defineConfig(({ mode, command}) => {
test: {
name: projectLabel,
globals: true,
environment: 'jsdom',
// Use happy-dom for faster tests (set VITEST_DOM=jsdom to use jsdom)
environment: process.env.VITEST_DOM || 'happy-dom',
retry: 2,
testTimeout: 20000,
hookTimeout: 10000,
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading