-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tests * fix lint errors * fix cypress and jest conflicting types * fix ts config excluding spec types * add message * yarn lint * add message check * raw cypress run * fix lint * test cypress ci * use rebuild * using build tag * remove node_modules when building cypress * test using npm * remove screenshot * ignore screenshots * remote testing dep * remove testing dep * rebuild with yarn * rebuild with npm * update binary flag * install canvas * separate task * capure cypress * upload downloads * use global font-family and update baseline pdfs * build examples, increase tolerance * update examples and reduce tolerance and threshold * update ci * empty message * undefined
- Loading branch information
Showing
23 changed files
with
997 additions
and
83 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
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 |
---|---|---|
|
@@ -12,4 +12,6 @@ package-lock.json | |
yarn-error.log | ||
.parcel-cache/ | ||
dist/ | ||
example/ | ||
examples/ | ||
cypress/ | ||
cypress.config.js |
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,50 @@ | ||
import path from "path"; | ||
import { defineConfig } from "cypress"; | ||
import ComparePdf, { ComparePdfConfig } from "compare-pdf"; | ||
|
||
const comparePDFConfig: ComparePdfConfig = { | ||
paths: { | ||
actualPdfRootFolder: path.join(process.cwd(), "cypress", "downloads"), | ||
baselinePdfRootFolder: path.join(process.cwd(), "cypress", "baseline"), | ||
actualPngRootFolder: path.join( | ||
process.cwd(), | ||
"cypress", | ||
"downloads", | ||
"png" | ||
), | ||
baselinePngRootFolder: path.join( | ||
process.cwd(), | ||
"cypress", | ||
"baseline", | ||
"png" | ||
), | ||
diffPngRootFolder: path.join(process.cwd(), "cypress", "baseline", "diff"), | ||
}, | ||
settings: { | ||
imageEngine: "native", | ||
density: 150, | ||
quality: 80, | ||
tolerance: 0, | ||
threshold: 0.1, | ||
cleanPngPaths: false, | ||
matchPageCount: true, | ||
disableFontFace: true, | ||
verbosity: 0, | ||
}, | ||
}; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on) { | ||
on("task", { | ||
async compareFile(filename: string) { | ||
const comparisonResults = await new ComparePdf(comparePDFConfig) | ||
.actualPdfFile(filename) | ||
.baselinePdfFile(filename) | ||
.compare(); | ||
return comparisonResults; | ||
}, | ||
}); | ||
}, | ||
}, | ||
}); |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,57 @@ | ||
import { slugify } from "../../examples/utils"; | ||
|
||
const getLink = (example: ExampleTest) => | ||
cy.get(`a[id='example-${slugify(example.title)}'`); | ||
const getButton = (example: ExampleTest) => getLink(example).find("button"); | ||
|
||
interface ExampleTest { | ||
title: string; | ||
filename: string; | ||
} | ||
|
||
interface ComparisonResult { | ||
status: "passed" | "failed"; | ||
message?: string; | ||
} | ||
|
||
export const examples: ExampleTest[] = [ | ||
{ | ||
title: "Using usePDF hook", | ||
filename: "usepdf-example.pdf", | ||
}, | ||
{ | ||
title: "Using default function", | ||
filename: "function-example.pdf", | ||
}, | ||
{ | ||
title: "Multipage support", | ||
filename: "multipage-example.pdf", | ||
}, | ||
{ | ||
title: "Advanced options", | ||
filename: "advanced-example.pdf", | ||
}, | ||
]; | ||
|
||
describe("template spec", () => { | ||
before(() => { | ||
cy.visit("http://localhost:1234"); | ||
}); | ||
|
||
it("pdfs must mach baseline", () => { | ||
examples.forEach((example) => { | ||
getLink(example).should("be.visible"); | ||
getButton(example).should("be.visible"); | ||
getButton(example).click(); | ||
}); | ||
cy.wait(10000); | ||
examples.forEach((example) => { | ||
cy.task("compareFile", example.filename).then( | ||
(result: ComparisonResult) => { | ||
expect(result.message).to.be.undefined; | ||
expect(result.status).to.equal("passed"); | ||
} | ||
); | ||
}); | ||
}); | ||
}); |
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,37 @@ | ||
/// <reference types="cypress" /> | ||
// *********************************************** | ||
// This example commands.ts shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add('login', (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This will overwrite an existing command -- | ||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) | ||
// | ||
// declare global { | ||
// namespace Cypress { | ||
// interface Chainable { | ||
// login(email: string, password: string): Chainable<void> | ||
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element> | ||
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element> | ||
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element> | ||
// } | ||
// } | ||
// } |
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,20 @@ | ||
// *********************************************************** | ||
// This example support/e2e.ts is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import "./commands"; | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
h1, | ||
h3 { | ||
font-family: Arial, Helvetica, sans-serif; | ||
body { | ||
font-family: Helvetica, sans-serif; | ||
} | ||
|
||
h3 { | ||
|
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
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,28 @@ | ||
import { ExampleUsePDF } from "./ExampleUsePDF"; | ||
import { ExampleFunction } from "./ExampleFunction"; | ||
import { ExampleMultipage } from "./ExampleMultipage"; | ||
import { ExampleAdvanced } from "./ExampleAdvanced"; | ||
|
||
export interface Example { | ||
title: string; | ||
component: React.FC; | ||
} | ||
|
||
export const examples: Example[] = [ | ||
{ | ||
title: "Using usePDF hook", | ||
component: ExampleUsePDF, | ||
}, | ||
{ | ||
title: "Using default function", | ||
component: ExampleFunction, | ||
}, | ||
{ | ||
title: "Multipage support", | ||
component: ExampleMultipage, | ||
}, | ||
{ | ||
title: "Advanced options", | ||
component: ExampleAdvanced, | ||
}, | ||
]; |
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 @@ | ||
export const slugify = (text: string) => text.toLowerCase().replace(/\s/g, "-"); |
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
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
Oops, something went wrong.