Skip to content

Commit

Permalink
✅ Add real basic integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Richard committed Oct 10, 2017
1 parent 419b8e2 commit fe72a8d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -8,11 +8,13 @@
"lint:js": "eslint --ext .js,.vue,.html calendar datepicker tests docs",
"lint:sass": "sass-lint -q -v",
"pretest": "npm run lint",
"test": "npm run docs:generate",
"test": "npm run unit && npm run integration",
"posttest": "npm run docs:generate",
"start": "npm run docs",
"docs": "NODE_ENV=dev nuxt -c docs/nuxt.config.js",
"docs:generate": "nuxt generate -c docs/nuxt.config.js",
"unit": "karma start tests/unit/karma.conf.js --single-run"
"unit": "karma start tests/unit/karma.conf.js --single-run",
"integration": "ava tests/integration"
},
"repository": {
"type": "git",
Expand All @@ -37,6 +39,7 @@
"devDependencies": {
"@nuxtjs/markdownit": "^1.1.2",
"@nuxtjs/pwa": "^0.2.1",
"ava": "^0.22.0",
"babel-eslint": "^8.0.0",
"babel-loader": "^7.1.2",
"chai": "^4.1.2",
Expand Down
32 changes: 32 additions & 0 deletions tests/integration/calendar.js
@@ -0,0 +1,32 @@
import test from 'ava';
import puppeteer from 'puppeteer';
import server from '../test-server';

// Set up a new server for each test
test.cb.beforeEach(t => {
t.context.port = ~~(Math.random() * 1000) + 8000; // eslint-disable-line no-param-reassign
t.context[`server-${t.context.port}`] = server.listen(t.context.port, 'localhost', () => { // eslint-disable-line no-param-reassign
t.end();
});
});

// Break down server after each test
test.afterEach.cb(t => {
t.context[`server-${t.context.port}`].close();
t.end();
});

test('Today has focus', async t => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(`http://localhost:${t.context.port}`);
await page.press('Tab');

const active = await page.evaluate(() => {
return document.activeElement;
});

await browser.close();

t.is(active._prevClass, 'calendar__link');
});

0 comments on commit fe72a8d

Please sign in to comment.