Skip to content

Commit

Permalink
set up e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Apr 5, 2021
1 parent 666d8f8 commit c4e9599
Show file tree
Hide file tree
Showing 16 changed files with 721 additions and 27 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
4 changes: 4 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"screenshotOnRunFailure": false,
"video": false
}
Empty file added cypress/fixtures/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions cypress/integration/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path="../support/index.d.ts" />

it("works", () => {
cy.qes().should("eq", 2);
});
22 changes: 22 additions & 0 deletions cypress/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ***********************************************
// This example commands.js 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) => { ... })

Cypress.Commands.add("qes", (input) => {
cy.visit("./e2e/index.html", {
onBeforeLoad:
typeof input !== "undefined"
? (win) => {
win.QES_INPUT = input;
}
: undefined,
});
return cy.window().its("QES_OUTPUT");
});
12 changes: 12 additions & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="cypress" />

declare namespace Cypress {
interface Chainable {
qes(input?: any): Chainable<any>;
}

interface ApplicationWindow {
QES_INPUT?: any;
QES_OUTPUT?: any;
}
}
20 changes: 20 additions & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js 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')
1 change: 1 addition & 0 deletions e2e/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script src="./dist/qes-e2e.umd.development.js"></script>
15 changes: 15 additions & 0 deletions e2e/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getQuickJS } from "quickjs-emscripten";
declare global {
interface Window {
QES_INPUT?: any;
QES_OUTPUT?: any;
}
}

async function main() {
const quickjs = await getQuickJS();
const result = quickjs.evalCode("1 + 1");
window.QES_OUTPUT = result;
}

main();
8 changes: 8 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "qes-e2e",
"author": "rot1024",
"private": true,
"scripts": {
"build": "tsdx build --entry index.ts --format umd"
}
}
12 changes: 12 additions & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"include": [
"."
],
"exclude": [
"dist"
],
"compilerOptions": {
"rootDir": "."
}
}
9 changes: 9 additions & 0 deletions e2e/tsdx.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
rollup(config) {
// https://github.com/formium/tsdx/issues/179
if (config.output.format === 'umd') {
delete config.external;
}
return config;
}
}
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
"lint": "tsdx lint",
"prepare": "tsdx build",
"size": "size-limit",
"analyze": "size-limit --why"
"analyze": "size-limit --why",
"e2e:build": "yarn --cwd e2e run build",
"e2e:test": "cypress run"
},
"peerDependencies": {
"quickjs-emscripten": "*"
},
"peerDependencies": {},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
Expand All @@ -46,7 +50,9 @@
],
"devDependencies": {
"@size-limit/preset-small-lib": "^4.10.2",
"cypress": "^6.8.0",
"husky": "^6.0.0",
"quickjs-emscripten": "^0.11.0",
"size-limit": "^4.10.2",
"tsdx": "^0.14.1",
"tslib": "^2.1.0",
Expand Down
12 changes: 10 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"include": ["src", "types"],
"include": [
"src",
"types"
],
"compilerOptions": {
"module": "esnext",
"lib": ["dom", "esnext"],
"lib": [
"dom",
"esnext"
],
"importHelpers": true,
// output .d.ts declaration files for consumers
"declaration": true,
Expand Down Expand Up @@ -31,5 +37,7 @@
"forceConsistentCasingInFileNames": true,
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true,
// suppress warning in Cypress
"baseUrl": "./src"
}
}
Loading

0 comments on commit c4e9599

Please sign in to comment.