From fe72a8db28aa43c0ae4676c72e71bda18e622f24 Mon Sep 17 00:00:00 2001 From: Sam Richard Date: Tue, 10 Oct 2017 16:39:30 -0500 Subject: [PATCH] :white_check_mark: Add real basic integration tests --- package.json | 7 +++++-- tests/integration/calendar.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tests/integration/calendar.js diff --git a/package.json b/package.json index ce16ed8..513a0c5 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/tests/integration/calendar.js b/tests/integration/calendar.js new file mode 100644 index 0000000..3fc99ba --- /dev/null +++ b/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'); +});