Skip to content

Commit

Permalink
WIP: test(image-io): add bio-rad browser test
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Oct 5, 2023
1 parent a8a8015 commit c044d2d
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/image-io/typescript/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
defaultCommandTimeout: 8000,
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
69 changes: 69 additions & 0 deletions packages/image-io/typescript/cypress/e2e/bio-rad.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { demoServer } from './common.ts'

describe('compareImages', () => {
beforeEach(function() {
cy.visit(demoServer)

const testPathPrefix = '../test/data/input/'

const testImageFiles = [
'cake_easy.iwi.cbor',
'cake_hard.iwi.cbor',
'cake_easy.png',
'cake_hard.png',
'apple.jpg',
'orange.jpg',
]
testImageFiles.forEach((fileName) => {
cy.readFile(`${testPathPrefix}${fileName}`, null).as(fileName)
})
})

it('Runs on double images', function () {
cy.get('sl-tab[panel="compareImages-panel"]').click()

const testFile = { contents: new Uint8Array(this['cake_easy.iwi.cbor']), fileName: 'cake_easy.iwi.cbor' }
cy.get('#compareImagesInputs input[name="test-image-file"]').selectFile([testFile,], { force: true })
cy.get('#compareImages-test-image-details').should('contain', 'imageType')

const baselineFile = { contents: new Uint8Array(this['cake_hard.iwi.cbor']), fileName: 'cake_hard.iwi.cbor' }
cy.get('#compareImagesInputs input[name="baseline-images-file"]').selectFile([baselineFile,], { force: true })
cy.get('#compareImages-baseline-images-details').should('contain', 'imageType')

cy.get('#compareImagesInputs sl-button[name="run"]').click()

cy.get('#compareImages-metrics-details').should('contain', '"almostEqual": false')
})

it('Runs on uint8 images', function () {
cy.get('sl-tab[panel="compareImages-panel"]').click()

const testFile = { contents: new Uint8Array(this['cake_easy.png']), fileName: 'cake_easy.png' }
cy.get('#compareImagesInputs input[name="test-image-file"]').selectFile([testFile,], { force: true })
cy.get('#compareImages-test-image-details').should('contain', 'imageType')

const baselineFile = { contents: new Uint8Array(this['cake_hard.png']), fileName: 'cake_hard.png' }
cy.get('#compareImagesInputs input[name="baseline-images-file"]').selectFile([baselineFile,], { force: true })
cy.get('#compareImages-baseline-images-details').should('contain', 'imageType')

cy.get('#compareImagesInputs sl-button[name="run"]').click()

cy.get('#compareImages-metrics-details').should('contain', '"almostEqual": false')
})

it('Runs on RGB images', function () {
cy.get('sl-tab[panel="compareImages-panel"]').click()

const testFile = { contents: new Uint8Array(this['apple.jpg']), fileName: 'apple.jpg' }
cy.get('#compareImagesInputs input[name="test-image-file"]').selectFile([testFile,], { force: true })
cy.get('#compareImages-test-image-details').should('contain', 'imageType')

const baselineFile = { contents: new Uint8Array(this['orange.jpg']), fileName: 'orange.jpg' }
cy.get('#compareImagesInputs input[name="baseline-images-file"]').selectFile([baselineFile,], { force: true })
cy.get('#compareImages-baseline-images-details').should('contain', 'imageType')

cy.get('#compareImagesInputs sl-button[name="run"]').click()

cy.get('#compareImages-metrics-details').should('contain', '"almostEqual": false')
})
})
1 change: 1 addition & 0 deletions packages/image-io/typescript/cypress/e2e/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const demoServer = 'http://localhost:5173'
37 changes: 37 additions & 0 deletions packages/image-io/typescript/cypress/support/commands.ts
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>
// }
// }
// }
31 changes: 31 additions & 0 deletions packages/image-io/typescript/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ***********************************************************
// 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')

Cypress.on('uncaught:exception', (err, runnable) => {
// we expect a 3rd party library error with message 'list not defined'
// and don't want to fail the test so we return false
if (err.message.includes('ResizeObserver loop completed with undelivered notifications')) {
return false
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
})

12 changes: 12 additions & 0 deletions packages/image-io/typescript/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"include": [
"**/*.ts"
],
"compilerOptions": {
"noEmit": false,
"sourceMap": false,
"inlineSourceMap": true,
"types": ["cypress"]
},
}
3 changes: 2 additions & 1 deletion packages/image-io/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@shoelace-style/shoelace": "^2.5.2",
"@types/node": "^20.2.5",
"ava": "^5.3.1",
"cypress": "^13.3.0",
"debug": "^4.3.4",
"rollup": "^3.9.0",
"rollup-plugin-copy": "^3.4.0",
Expand All @@ -59,4 +60,4 @@
"type": "git",
"url": "https://github.com/InsightSoftwareConsortium/itk-wasm"
}
}
}

0 comments on commit c044d2d

Please sign in to comment.