Add testclient unit tests (#957)

This commit is contained in:
Konrad Borowski 2017-06-28 02:43:54 +02:00 committed by Guangcong Luo
parent 2fac7642f6
commit 156b5bf3d5
4 changed files with 49 additions and 6 deletions

View File

@ -1,8 +1,21 @@
sudo: false
language: node_js
dist: trusty
node_js:
- "4"
- "8"
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
cache:
directories:
- node_modules
- eslint-cache
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
script:
- "npm test"
- "npm run-script testcafe"

View File

@ -8,10 +8,16 @@ const child_process = require("child_process");
const rootDir = path.resolve(__dirname, '..');
const dataDir = path.resolve(rootDir, 'data');
const repositoryDir = path.resolve(dataDir, 'Pokemon-Showdown');
if (!fs.existsSync(repositoryDir)) {
child_process.execSync('git clone https://github.com/Zarel/Pokemon-Showdown.git', {
cwd: dataDir,
});
}
process.stdout.write("Syncing data from Git repository... ");
child_process.execSync('git pull', {
cwd: path.resolve(dataDir, 'Pokemon-Showdown'),
});
child_process.execSync('git pull', {cwd: repositoryDir});
console.log("DONE");
const Tools = require('../data/Pokemon-Showdown/sim/dex');

View File

@ -10,11 +10,13 @@
},
"scripts": {
"test": "eslint --config=.eslintrc.js --cache --cache-file=eslint-cache/base js/*.js data/graphics.js && eslint --config=githooks/.eslintrc.js --cache --cache-file=eslint-cache/build githooks/update githooks/build-indexes",
"fix": "eslint --config=.eslintrc.js --fix js/*.js data/graphics.js && eslint --config=githooks/.eslintrc.js --fix githooks/update githooks/build-indexes"
"fix": "eslint --config=.eslintrc.js --fix js/*.js data/graphics.js && eslint --config=githooks/.eslintrc.js --fix githooks/update githooks/build-indexes",
"testcafe": "githooks/build-indexes && testcafe chrome test/"
},
"dependencies": {},
"devDependencies": {
"eslint": "^3.2.2"
"eslint": "^3.2.2",
"testcafe": "^0.16.1"
},
"private": true
}

22
test/test.ts Normal file
View File

@ -0,0 +1,22 @@
import { Selector } from 'testcafe';
fixture('Pokemon Showdown')
.page('../testclient.html?~~localhost');
const expectedTeam = `=== Untitled 1 ===
Abomasnow-Mega @ Abomasite\x20\x20
Ability: Snow Warning`;
test('Teambuilder works', async t => {
await t.click('[name="close"]')
.click('[value="teambuilder"]')
.click('[name="newTop"]')
.click('[name="addPokemon"]')
.click('[data-entry="pokemon|Abomasnow-Mega"]')
.click('[name="back"]')
.click('[name="back"]')
.click('[name="backup"]');
await t.expect((await Selector('textarea').value).trim()).eql(expectedTeam);
});