From a043c853b6bbc084a3897c1da68823da753782ac Mon Sep 17 00:00:00 2001 From: Dmitry Kuzin Date: Mon, 22 Apr 2024 17:21:10 +0400 Subject: [PATCH 1/4] Update jest to support queueMircotask --- package.json | 6 +++--- tests/flat_signaturepad.test.ts | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3e352a5..80e7065 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "survey-core": "latest" }, "devDependencies": { - "@types/jest": "^23.3.3", + "@types/jest": "^25.1.5", "@types/lodash": "4.14.121", "@types/node": "7.0.4", "@typescript-eslint/eslint-plugin": "^4.31.0", @@ -37,13 +37,13 @@ "eslint": "^7.32.0", "generate-json-webpack-plugin": "0.2.1", "husky": "^2.7.0", - "jest": "^23.6.0", + "jest": "^25.2.7", "jest-junit": "^16.0.0", "live-server": "^1.2.2", "rimraf": "2.5.4", "standard-version": "^8.0.1", "surveyjs-doc-generator": "git+https://github.com/surveyjs/surveyjs-doc-generator.git", - "ts-jest": "^23.10.3", + "ts-jest": "^25.2.7", "ts-loader": "2.3.4", "typescript": "^4.2.2", "webpack": "2.2.1", diff --git a/tests/flat_signaturepad.test.ts b/tests/flat_signaturepad.test.ts index 13ea6f8..06916c5 100644 --- a/tests/flat_signaturepad.test.ts +++ b/tests/flat_signaturepad.test.ts @@ -51,6 +51,8 @@ test('Check signaturepad', async () => { test('Check signaturepad with backgroundImage', async () => { SurveyHelper.shouldConvertImageToPng = false; + const oldXMLSerializer = window.XMLSerializer; + window.XMLSerializer = undefined as any; let json: any = { questions: [ { @@ -85,4 +87,5 @@ test('Check signaturepad with backgroundImage', async () => { TestHelper.equalRect(expect, htmlBrick, assumeHTML); TestHelper.equalRect(expect, backgroundImageBrick, assumeHTML); SurveyHelper.shouldConvertImageToPng = true; + window.XMLSerializer = oldXMLSerializer }); \ No newline at end of file From d8af4381b5c7530ce8dec49ffbd9e9b5cd216372 Mon Sep 17 00:00:00 2001 From: Dmitry Kuzin Date: Mon, 22 Apr 2024 17:34:32 +0400 Subject: [PATCH 2/4] Do not use row.visibleElement in pdf --- src/flat_layout/flat_survey.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/flat_layout/flat_survey.ts b/src/flat_layout/flat_survey.ts index 4f64ad5..d0dc334 100644 --- a/src/flat_layout/flat_survey.ts +++ b/src/flat_layout/flat_survey.ts @@ -70,12 +70,13 @@ export class FlatSurvey { const width: number = SurveyHelper.getPageAvailableWidth(controller); let nextMarginLeft: number = controller.margins.left; const rowFlats: IPdfBrick[] = []; - for (let i: number = 0; i < row.visibleElements.length; i++) { - let element: IElement = row.visibleElements[i]; + const visibleElements = row.elements.filter(el => el.isVisible); + for (let i: number = 0; i < visibleElements.length; i++) { + let element: IElement = visibleElements[i]; if (!element.isVisible) continue; const persWidth: number = SurveyHelper.parseWidth(element.renderWidth, - width - (row.visibleElements.length - 1) * controller.unitWidth, - row.visibleElements.length); + width - (visibleElements.length - 1) * controller.unitWidth, + visibleElements.length); controller.margins.left = nextMarginLeft + ((i !== 0) ? controller.unitWidth : 0); controller.margins.right = controller.paperWidth - controller.margins.left - persWidth; currPoint.xLeft = controller.margins.left; From b7415be96092d99a963fee2afeeb90d0d0e4a994 Mon Sep 17 00:00:00 2001 From: Dmitry Kuzin Date: Tue, 23 Apr 2024 01:43:00 +0400 Subject: [PATCH 3/4] Revert "Update jest to support queueMircotask" This reverts commit a043c853b6bbc084a3897c1da68823da753782ac. --- package.json | 6 +++--- tests/flat_signaturepad.test.ts | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 80e7065..3e352a5 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "survey-core": "latest" }, "devDependencies": { - "@types/jest": "^25.1.5", + "@types/jest": "^23.3.3", "@types/lodash": "4.14.121", "@types/node": "7.0.4", "@typescript-eslint/eslint-plugin": "^4.31.0", @@ -37,13 +37,13 @@ "eslint": "^7.32.0", "generate-json-webpack-plugin": "0.2.1", "husky": "^2.7.0", - "jest": "^25.2.7", + "jest": "^23.6.0", "jest-junit": "^16.0.0", "live-server": "^1.2.2", "rimraf": "2.5.4", "standard-version": "^8.0.1", "surveyjs-doc-generator": "git+https://github.com/surveyjs/surveyjs-doc-generator.git", - "ts-jest": "^25.2.7", + "ts-jest": "^23.10.3", "ts-loader": "2.3.4", "typescript": "^4.2.2", "webpack": "2.2.1", diff --git a/tests/flat_signaturepad.test.ts b/tests/flat_signaturepad.test.ts index 06916c5..13ea6f8 100644 --- a/tests/flat_signaturepad.test.ts +++ b/tests/flat_signaturepad.test.ts @@ -51,8 +51,6 @@ test('Check signaturepad', async () => { test('Check signaturepad with backgroundImage', async () => { SurveyHelper.shouldConvertImageToPng = false; - const oldXMLSerializer = window.XMLSerializer; - window.XMLSerializer = undefined as any; let json: any = { questions: [ { @@ -87,5 +85,4 @@ test('Check signaturepad with backgroundImage', async () => { TestHelper.equalRect(expect, htmlBrick, assumeHTML); TestHelper.equalRect(expect, backgroundImageBrick, assumeHTML); SurveyHelper.shouldConvertImageToPng = true; - window.XMLSerializer = oldXMLSerializer }); \ No newline at end of file From 23f5b43037bdb921a39154fbd881071f40e54cb1 Mon Sep 17 00:00:00 2001 From: Dmitry Kuzin Date: Tue, 23 Apr 2024 01:51:35 +0400 Subject: [PATCH 4/4] Mock queueMircotask in unit tests --- jest.config.js | 1 + setupFile.js | 1 + 2 files changed, 2 insertions(+) create mode 100644 setupFile.js diff --git a/jest.config.js b/jest.config.js index 429a65d..e36bf55 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,6 +4,7 @@ module.exports = { tsConfig: "tsconfig.test.json" } }, + setupFiles: ["/setupFile.js"], reporters: [ "default", [ "jest-junit", { diff --git a/setupFile.js b/setupFile.js new file mode 100644 index 0000000..0acf8ed --- /dev/null +++ b/setupFile.js @@ -0,0 +1 @@ +global.queueMicrotask = (cb) => { cb(); } \ No newline at end of file