Skip to content

Commit

Permalink
feat: initial cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarpl committed Jul 21, 2021
1 parent d6981e3 commit 47a25c9
Show file tree
Hide file tree
Showing 8 changed files with 1,146 additions and 313 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"javascript.suggest.autoImports": false,
"javascript.suggest.includeCompletionsForImportStatements": false,
"javascript.suggest.completeFunctionCalls": false,
"javascript.suggest.names": false,
"javascript.suggest.enabled": false
}
11 changes: 11 additions & 0 deletions cypress/integration/basic_hotkey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types="cypress" />

describe('Basic hotkey', () => {
it('Activates when key pressed', () => {
cy.visit('http://localhost:9000/')
cy.window().then((win) => {
//@ts-ignore
win.bindCombo('KeyA', {})
})
})
})
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
"license-validate": "yarn sofie-licensecheck",
"validate:dependencies": "yarn audit --groups dependencies && yarn license-validate",
"validate:dev-dependencies": "yarn audit --groups devDependencies",
"test": "cypress open",
"test": "concurrently --prefix \"[{name}]\" --names \"webpack,cypress\" -c \"bgBlue.bold,bgGreen.bold\" \"yarn start\" \"yarn cypress\"",
"cypress": "cypress open",
"release": "standard-version --commit-all",
"prepareChangelog": "yarn release --prerelease"
"changelog": "yarn release --prerelease"
},
"devDependencies": {
"@sofie-automation/code-standard-preset": "^0.4.2",
"concurrently": "^6.2.0",
"cypress": "^8.0.0",
"rimraf": "^3.0.2",
"standard-version": "^9.3.1",
"ts-loader": "8.2.0",
"typescript": "4.2.4",
"webpack": "5.45.1",
"webpack": "^4.46.0",
"webpack-cli": "4.5.0",
"webpack-dev-server": "3.11.2",
"yargs": "^17.0.1"
Expand Down
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ function keyDown(e: KeyboardEvent) {

async function getKeyboardLayoutMap() {
if ('keyboard' in navigator && typeof navigator.keyboard.getLayoutMap === 'function') {
keyboardLayoutMap = await navigator.keyboard.getLayoutMap()
try {
keyboardLayoutMap = await navigator.keyboard.getLayoutMap()
} catch (e) {
console.error('Could not get keyboard layout map.')
}
}
}

Expand Down Expand Up @@ -295,9 +299,7 @@ async function init() {
passive: false,
})
window.addEventListener('layoutchange', () => {
getKeyboardLayoutMap().catch((reason) => {
throw new Error(reason)
})
getKeyboardLayoutMap().catch(console.error)
})
await getKeyboardLayoutMap()

Expand Down
52 changes: 52 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
<!DOCTYPE html>
<script src="simonsson.js"></script>
<style>
#result .binding {
display: flex;
}
#result .binding .combo,
#result .binding .hit {
flex: 1 1;
}
#result .binding .hit.hot {
background-color: black;
font-weight: bold;
color: white;
}
</style>
<template id="binding">
<div class="binding">
<div class="combo">
<!-- Key combination -->
</div>
<div class="hit">
<!-- Was activated? -->
</div>
</div>
</template>
<p id="mounted">Not initialized</p>
<div id="result"></div>
<script>
const bindings = []
Simonsson.init().then(() => {
document.getElementById('mounted').textContent = 'Simonsson initialized'
})

const bindCombo = (combo, options, clb) => {
const template = document.getElementById('binding')
const bindRow = template.content.cloneNode(true)
bindRow.querySelector('.combo').textContent = combo
bindRow.querySelector('.hit').textContent = 'No'
document.getElementById('result').appendChild(bindRow)
const inserted = document.getElementById('result').lastElementChild
Simonsson.bind(
combo,
() => {
const hitCell = inserted.querySelector('.hit')
hitCell.textContent = 'Yes'
hitCell.classList.add('hot')
if (typeof clb === 'function') clb()
},
options
)
}
window.bindCombo = bindCombo
</script>
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"extends": "./tsconfig.build.json",
"include": ["src/**/*.ts"],
"include": ["src/**/*.ts", "cypress/**/*.ts"],
"exclude": ["node_modules/**"],
"compilerOptions": {
"sourceMap": true,
"module": "UMD",
"lib": ["dom", "es6", "es2016"],
"types": []
"types": ["cypress"]
}
}
5 changes: 1 addition & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ module.exports = {
},
devServer: {
contentBase: [
path.join(__dirname, 'demo'),
path.join(__dirname, 'assets'),
path.join(__dirname, 'dist'),
__dirname
path.join(__dirname, 'test'),
],
compress: true,
port: 9000,
Expand Down
Loading

0 comments on commit 47a25c9

Please sign in to comment.