Commit 0f5f53d3 authored by *Kim's avatar *Kim 🦎

Initial code for tests, etc

parents
# EditorConfig is awesome: http://EditorConfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
quote_type = single
curly_bracket_next_line = false
spaces_around_operators = true
spaces_around_brackets = false
[*.md]
indent_style = space
indent_size = 2
max_line_length = 80
[*.yml]
indent_style = space
[{package,bower}.json]
indent_style = space
indent_size = 2
node_modules
*.log
todo*
const { app, BrowserWindow } = require('electron');
app.on('ready', () => {
win = new BrowserWindow({
width: 800,
height: 600,
show: process.env.npm_lifecycle_event !== 'test',
autoHideMenuBar: true,
});
if (
process.env.npm_lifecycle_event !== 'test' &&
process.env.NODE_ENV === 'development'
) {
win.webContents.openDevTools();
}
win.loadFile('app/index.html');
});
const { Display } = require('@kymera/core');
<!doctype html>
<title>Test</title>
<h1>Hello World!</h1>
{
"name": "@kymera/simulator",
"version": "0.0.0",
"description": "Simulator for the Kymera wearables",
"main": "app.js",
"repository": "https://gitlab.com/chameleoid/kymera/simulator.git",
"author": "*Kim Zick (rummik) <[email protected]>",
"license": "MPL-2.0",
"scripts": {
"start": "electron .",
"start:watch": "nodemon --exec 'yarn start'",
"test": "mocha",
"test:watch": "nodemon --exec 'yarn test'"
},
"dependencies": {
"@kymera/core": "*",
"electron": "^3.0.9"
},
"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-webdriver": "^1.2.0",
"electron-chromedriver": "^4.0.0-beta.1",
"mocha": "^5.2.0",
"nodemon": "^1.18.6",
"selenium-webdriver": "^4.0.0-alpha.1",
"spectron": "^5.0.0"
}
}
{
pkgs ? import <nixpkgs> {},
stdenv ? pkgs.stdenv,
chrootenv ? pkgs.callPackage <nixpkgs/pkgs/build-support/build-fhs-userenv/chrootenv> {},
buildEnv ? pkgs.buildEnv,
mkDerivation ? stdenv.mkDerivation,
mkShell ? pkgs.mkShell,
makeLibraryPath ? stdenv.lib.makeLibraryPath,
is64bit ? stdenv.is64bit,
optionalString ? pkgs.lib.optionalString,
writeScript ? pkgs.writeScript,
coreutils ? pkgs.coreutils,
glibc ? pkgs.glibc,
glibc32 ? pkgs.pkgsi686Linux.glibc,
}:
let
fhs-init = writeScript "fhs-init" ''
#! ${stdenv.shell}
cd $FHS_PWD
for path in ${fhs-lib}/* /host/*; do
out="/''${path##*/}"
[ -e "$out" ] || ${coreutils}/bin/ln -s "$path" "$out"
done
exec zsh
'';
fhs-lib = mkDerivation {
name = "fhs-lib";
buildCommand = ''
mkdir -p -m0755 $out
ln -s ${glibc32}/lib $out/lib32
${optionalString (is64bit) "ln -s ${glibc}/lib $out/lib64"}
ln -s $out/lib${if is64bit then "64" else "32"} $out/lib
'';
};
in
mkShell rec {
buildInputs = with pkgs;
atomEnv.packages ++
[
libuv
v8
gtk3-x11
at-spi2-atk
nodejs-8_x
(yarn.override { nodejs = nodejs-8_x; })
];
shellHook = ''
export PATH="$PWD/node_modules/.bin/:$PATH"
export NODE_ENV=development
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath buildInputs}
export FHS_PWD=$PWD
export CXXFLAGS=-I${pkgs.nodejs-8_x}/include/node
exec ${chrootenv} ${fhs-init}
'';
}
module.exports = function chaiSpectron(app) {
return function chaiSpectronHelper(chai, utils) {
const Assertion = chai.Assertion;
const addProperty = (...args) => Assertion.addProperty(...args);
const addMethod = (...args) => Assertion.addMethod(...args);
const overwriteMethod = (...args) => Assertion.overwriteMethod(...args);
const overwriteProperty = (...args) => Assertion.overwriteProperty(...args);
function requireDOMFlag(_this, word) {
if (!utils.flag(_this, 'dom')) {
throw new Error(`Can only test ${word} of dom elements`);
}
}
addProperty('dom', function dom() {
utils.flag(this, 'dom', true);
});
addMethod('text', async function spectronText(expected) {
requireDOMFlag(this, 'text');
const selector = utils.flag(this, 'object');
const getText = await app.client.getText(selector);
const textArray = (getText instanceof Array) ? getText : [ getText ];
this.assert(
textArray.some(text => text === expected),
`Expected element <${selector}> to contain text "${expected}", but only found: ${textArray}`,
`Expected element <${selector}> not to contain text "${expected}", but found: ${textArray}`,
);
});
overwriteProperty('exist', function(_super) {
return async function domExist() {
if (!utils.flag(this, 'dom') || !utils.flag(this, 'object')) {
return _super.call(this);
}
const selector = utils.flag(this, 'object');
this.assert(
await app.client.isExisting(selector),
`Expected element <${selector}> to exist`,
`Expected element <${selector}> to not exist`,
);
};
});
};
};
const chai = require('chai');
const { expect } = chai;
const { Application } = require('spectron');
const electron = require('electron');
const path = require('path');
const chaiSpectron = require('./helpers/chai-spectron');
const app = new Application({
path: electron,
args: [ path.join(__dirname, '..') ],
});
chai.use(require('chai-as-promised'));
chai.use(chaiSpectron(app));
describe('Test', function() {
this.timeout(20000);
beforeEach(async () => await app.start());
afterEach(async () => await app.stop());
it('should run a test', () => {
expect(true).to.equal(true);
});
it('should see test title', async () => {
await expect(app.client.getTitle()).to.eventually.equal('Test');
});
it('should see "Hello World!"', async () => {
await expect('h1').dom.to.have.text('Hello World!');
await expect('h1').dom.to.exist;
});
});
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment