mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-15 17:42:15 +08:00

* feat(e2e-tests) simplify e2e test structure * test(badge) add basic e2e test * test(button) update e2e test to new structure * test(card) add basic e2e test * test(checkbox) add basic e2e test * chore(e2e-test) update path to e2e module in run-e2e * fix(button) update toolbar e2e deps * fix(e2e-test) update path in snapshot script * feat(e2e-test) move e2e scripts into scripts/e2e * test(chip) add basic e2e test * test(content) add basic e2e test * test(datetime) add basic e2e test * style(e2e-test) use consistent title/header in e2e test pages * test(fab) add basic e2e test * fix(e2e-test) don't run e2e script when required * test(grid) add basic e2e test * test(icon) add basic e2e test * test(input) add basic e2e test * style(e2e-test) use consistent e2e test header titles * test(list) add basic e2e test * test(menu) add basic e2e test * test(modal) add basic e2e test * feat(e2e-test) add navigate export to e2e module * feat(e2e-test) add present method to Page class * test(popover) add basic e2e test * test(menu) add present left menu e2e test * test(radio) add basic e2e test * test(range) add basic e2e test * test(searchbar) add basic e2e test * test(segment) add basic e2e test * test(select) add basic e2e test * test(modal) add shows modal e2e test * test(slides) add basic e2e test * test(spinner) add basic/color e2e tests * test(tabs) add basic e2e test * test(toast) add basic e2e test * test(toggle) add basic e2e test * test(toolbar) add basic e2e test * docs(e2e-test) update e2e readme to reflect simplest test * test(card) update basic e2e test * chore(e2e-test) remove run-e2e script * test(components): move remaining component tests to index files * chore(package): add mocha to devDependencies * test(infinite-scroll) add basic e2e test * test(item-sliding) add basic e2e test * test(item) add basic/buttons e2e tests * test(nav) add basic e2e test * test(reorder) add basic e2e test * test(split-pane) add basic e2e test * chore() update declarations file * refactor(toast): reduce border-radius * chore(components): update components.d.ts
140 lines
3.2 KiB
JavaScript
140 lines
3.2 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const glob = require('glob');
|
|
const Mocha = require('mocha');
|
|
const path = require('path');
|
|
const webdriver = require('selenium-webdriver');
|
|
|
|
const Page = require('./e2e-test-page');
|
|
const Snapshot = require('./snapshot');
|
|
|
|
let driver;
|
|
let snapshot;
|
|
let specIndex = 0;
|
|
let takeScreenshots = false;
|
|
|
|
function startDevServer() {
|
|
const server = require('@stencil/dev-server/dist'); // TODO: fix after stencil-dev-server PR #16 is merged
|
|
const cmdArgs = ['--config', path.join(__dirname, '../stencil.config.js'), '--no-open'];
|
|
|
|
return server.run(cmdArgs);
|
|
}
|
|
|
|
function generateTestId() {
|
|
let chars = 'abcdefghjkmnpqrstuvwxyz';
|
|
let id = chars.charAt(Math.floor(Math.random() * chars.length));
|
|
chars += '0123456789';
|
|
while (id.length < 3) {
|
|
id += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
}
|
|
return id;
|
|
}
|
|
|
|
function getTestFiles() {
|
|
return new Promise((resolve, reject) => {
|
|
const src = path.join(__dirname, '../../src/**/e2e.js');
|
|
glob(src, (err, files) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(files);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function processCommandLine() {
|
|
process.argv.forEach(arg => {
|
|
if (arg === '--snapshot') {
|
|
takeScreenshots = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
function registerE2ETest(desc, tst) {
|
|
// NOTE: Do not use an arrow function here because: https://mochajs.org/#arrow-functions
|
|
it(desc, async function() {
|
|
await tst(driver);
|
|
if (takeScreenshots) {
|
|
await snapshot.takeScreenshot(driver, {
|
|
name: this.test.fullTitle(),
|
|
specIndex: specIndex++
|
|
});
|
|
}
|
|
return Promise.resolve(true);
|
|
});
|
|
}
|
|
|
|
function getTotalTests(suite) {
|
|
let ttl = suite.tests.length;
|
|
suite.suites.forEach(s => (ttl += getTotalTests(s)));
|
|
return ttl;
|
|
}
|
|
|
|
async function run() {
|
|
const mocha = new Mocha({
|
|
timeout: 5000,
|
|
slow: 2000
|
|
});
|
|
|
|
driver = new webdriver.Builder().forBrowser('chrome').build();
|
|
|
|
processCommandLine();
|
|
|
|
const devServer = await startDevServer();
|
|
|
|
const files = await getTestFiles();
|
|
files.forEach(f => mocha.addFile(f));
|
|
mocha.loadFiles(() => {
|
|
specIndex = 0;
|
|
|
|
snapshot = new Snapshot({
|
|
groupId: 'ionic-core',
|
|
appId: 'snapshots',
|
|
testId: generateTestId(),
|
|
domain: 'ionic-snapshot-go.appspot.com',
|
|
// domain: 'localhost:8080',
|
|
sleepBetweenSpecs: 750,
|
|
totalSpecs: getTotalTests(mocha.suite),
|
|
platformDefaults: {
|
|
browser: 'chrome',
|
|
platform: 'linux',
|
|
params: {
|
|
platform_id: 'chrome_400x800',
|
|
platform_index: 0,
|
|
platform_count: 1,
|
|
width: 400,
|
|
height: 800
|
|
}
|
|
},
|
|
accessKey: process.env.IONIC_SNAPSHOT_KEY
|
|
});
|
|
|
|
mocha.run(function(failures) {
|
|
process.on('exit', function() {
|
|
process.exit(failures); // exit with non-zero status if there were failures
|
|
});
|
|
if (takeScreenshots) {
|
|
snapshot.finish();
|
|
}
|
|
devServer.close();
|
|
driver.quit();
|
|
});
|
|
});
|
|
}
|
|
|
|
const navigate = url => driver => new Page(driver, url).navigate();
|
|
|
|
// Invoke run() only if executed directly i.e. `node ./scripts/e2e`
|
|
if (require.main === module) {
|
|
run();
|
|
}
|
|
|
|
module.exports = {
|
|
Page,
|
|
navigate,
|
|
register: registerE2ETest,
|
|
run: run
|
|
};
|