0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

test: add e2e test - testing ci mode

This commit is contained in:
Juan Picado @jotadeveloper 2018-02-08 22:24:34 +01:00
parent 784bcf8ecc
commit 27286a5bff
No known key found for this signature in database
GPG key ID: 18AC54485952D158
8 changed files with 105 additions and 0 deletions

View file

@ -29,8 +29,10 @@ test:
- yarn run test
- nvm alias default 8
- yarn run test
- yarn run test:e2e
- nvm alias default 9
- yarn run test
- yarn run test:e2e
- yarn run coverage:publish
- echo "machine github.com login verdacciobot password $GITHUB_TOKEN" > ~/.netrc
- cd website && yarn install && GIT_USER=verdacciobot USE_SSH=false yarn run publish-gh-pages

11
jest.e2e.config.js Normal file
View file

@ -0,0 +1,11 @@
/* eslint comma-dangle: 0 */
module.exports = {
'name': 'verdaccio-e2e-jest',
'verbose': true,
'collectCoverage': false,
'globalSetup': './test/e2e/setup.js',
'globalTeardown': './test/e2e/teardown.js',
'testEnvironment': './test/e2e/puppeteer_environment.js',
'testRegex': '(/test/e2e/e2e.*\\.spec)\\.js'
};

View file

@ -102,11 +102,13 @@
"jest": "22.1.4",
"jest-environment-jsdom": "22.1.4",
"jest-environment-jsdom-global": "1.0.3",
"jest-environment-node": "22.2.0",
"localstorage-memory": "1.0.2",
"node-sass": "4.7.2",
"normalize.css": "7.0.0",
"ora": "^1.4.0",
"prop-types": "15.6.0",
"puppeteer": "1.0.0",
"react": "16.2.0",
"react-dom": "16.2.0",
"react-hot-loader": "4.0.0-beta.17",
@ -145,6 +147,7 @@
"flow": "flow",
"pretest": "npm run code:build",
"test": "cross-env NODE_ENV=test BABEL_ENV=test jest --maxWorkers 2",
"test:e2e": "cross-env NODE_ENV=test BABEL_ENV=test jest --config ./jest.e2e.config.js --maxWorkers 2",
"test:unit": "cross-env NODE_ENV=test BABEL_ENV=test jest '(/test/unit.*\\.spec|/test/webui/.*\\.spec)\\.js' --maxWorkers 2",
"test:func": "cross-env NODE_ENV=test BABEL_ENV=test jest '(/test/functional.*\\.func)\\.js' --maxWorkers 2",
"pre:ci": "npm run lint && npm run build:webui",

24
test/e2e/e2e.spec.js Normal file
View file

@ -0,0 +1,24 @@
const timeout = 5000;
describe(
'/ (Home Page)',
() => {
let page;
beforeAll(async () => {
page = await global.__BROWSER__.newPage();
await page.goto('https://google.com');
}, timeout);
afterAll(async () => {
await page.close()
});
it('should load without error', async () => {
let text = await page.evaluate(() => document.body.textContent);
expect(text).toContain('google');
})
},
timeout
);

View file

@ -0,0 +1,37 @@
const chalk = require('chalk');
const NodeEnvironment = require('jest-environment-node');
const puppeteer = require('puppeteer');
const fs = require('fs');
const os = require('os');
const path = require('path');
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
class PuppeteerEnvironment extends NodeEnvironment {
constructor(config) {
super(config)
}
async setup() {
console.log(chalk.yellow('Setup Test Environment.'));
await super.setup();
const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf8');
if (!wsEndpoint) {
throw new Error('wsEndpoint not found')
}
this.global.__BROWSER__ = await puppeteer.connect({
browserWSEndpoint: wsEndpoint,
})
}
async teardown() {
console.log(chalk.yellow('Teardown Test Environment.'));
await super.teardown()
}
runScript(script) {
return super.runScript(script)
}
}
module.exports = PuppeteerEnvironment;

16
test/e2e/setup.js Normal file
View file

@ -0,0 +1,16 @@
const chalk = require('chalk');
const puppeteer = require('puppeteer');
const fs = require('fs');
const mkdirp = require('mkdirp');
const os = require('os');
const path = require('path');
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function() {
console.log(chalk.green('Setup Puppeteer'));
const browser = await puppeteer.launch({});
global.__BROWSER__ = browser;
mkdirp.sync(DIR);
fs.writeFileSync(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint());
};

12
test/e2e/teardown.js Normal file
View file

@ -0,0 +1,12 @@
const chalk = require('chalk');
const rimraf = require('rimraf');
const os = require('os');
const path = require('path');
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
module.exports = async function() {
console.log(chalk.green('Teardown Puppeteer'));
await global.__BROWSER__.close();
rimraf.sync(DIR)
};

BIN
yarn.lock

Binary file not shown.