Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nightwatch.js run local tests #1077

Merged
merged 26 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aa971a6
WIP(*): add packages to owrk with Nightwatch localy
adamszalapski Feb 7, 2019
e8d0e10
WIP(*): updateing nightwatch to work with local tests
adamszalapski Feb 7, 2019
54b5b6b
WIP(@bolt/components-video): update bolt-video test files
adamszalapski Feb 7, 2019
be2f86d
WIP(*): update nightwatch srcipts
adamszalapski Feb 7, 2019
51829f0
feat(*): run nightwatch tests on local
adamszalapski Feb 8, 2019
928ef69
test(@bolt/components-image): add basic tests to bolt-image
adamszalapski Feb 8, 2019
23c0407
Merge branch 'master' of https://github.com/bolt-design-system/bolt i…
adamszalapski Feb 8, 2019
220f935
refactor(@bolt/components-image): cleaning the code
adamszalapski Feb 8, 2019
2dca772
test(@bolt/components-image): update bolt-image size logic
adamszalapski Feb 8, 2019
5c7727f
test(*): update JEST config
adamszalapski Feb 8, 2019
07f4b3a
test(@bolt/components-image): update test logic
adamszalapski Feb 11, 2019
e3278ef
test(@bolt/components-image): update nightwatch test logic
adamszalapski Feb 11, 2019
327d487
chore(@bolt/components-figure): merge with master
adamszalapski Feb 12, 2019
a5ca6c3
test(@bolt/components-video): update test for bolt-video
adamszalapski Feb 14, 2019
3e0ee63
test(@bolt/components-video): update bolt-video test logic
adamszalapski Feb 14, 2019
501a0f1
test(*): update bolt-video test logic (working on local)
adamszalapski Feb 18, 2019
3ea81a6
fix(@bolt/components-video): fix for IE11 testing
adamszalapski Feb 18, 2019
d9c9eb1
test(@bolt/components-video): change second playback rate to trigger …
adamszalapski Feb 18, 2019
75f14ad
fix(@bolt/components-video): cHange test logic
adamszalapski Feb 19, 2019
bca829e
test(@bolt/components-video): update bolt-video test logic
adamszalapski Feb 19, 2019
c83729d
test(@bolt/components-video): update test logic
adamszalapski Feb 19, 2019
4b4da3f
refactor(@bolt/components-video): cleaning the code
adamszalapski Feb 19, 2019
e0e9cc5
chore(@bolt/components-video): fix prettier issues
adamszalapski Feb 19, 2019
67deb71
test(@bolt/components-video): update test logic for bolt-video
adamszalapski Feb 19, 2019
7f4b857
test(@bolt/components-video): update test
adamszalapski Feb 19, 2019
8a69d1d
Merge branch 'master' into feature/nightwatch-local-tests
sghoweri Feb 20, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions nightwatch.handle-results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
const { getGitSha } = require('ci-utils');
const fetch = require('node-fetch');
const https = require('https');

const gitSha = getGitSha(true);
const gitShaLong = getGitSha();

const {
SAUCE_USERNAME,
SAUCE_ACCESS_KEY,
// for push builds, or builds not triggered by a pull request, this is the name of the branch.
// for builds triggered by a pull request this is the name of the branch targeted by the pull request.
// for builds triggered by a tag, this is the same as the name of the tag(TRAVIS_TAG).
TRAVIS_BRANCH,
// if the current job is a pull request, the name of the branch from which the PR originated
// if the current job is a push build, this variable is empty("").
TRAVIS_PULL_REQUEST_BRANCH,
// The pull request number if the current job is a pull request, "false" if it’s not a pull request.
TRAVIS_PULL_REQUEST,
// The slug (in form: owner_name/repo_name) of the repository currently being built.
TRAVIS_REPO_SLUG,
// If the current build is for a git tag, this variable is set to the tag’s name
TRAVIS_TAG,
TRAVIS_BUILD_WEB_URL,
TRAVIS_JOB_NUMBER,
} = process.env;

const auth = Buffer.from(`${SAUCE_USERNAME}:${SAUCE_ACCESS_KEY}`).toString(
'base64',
);

/**
* @param {Object} client - Nightwatch instance @todo add link to API docs
* @param {function} callback
* @returns {void}
*/

async function handleNightwatchResults(client, callback) {
const currentTest = client.currentTest;
const sessionId = client.capabilities['webdriver.remote.sessionid'];
const { username, accessKey } = client.options;
const {
/** @type {string} - Name of test */
name,
/** @type {string} - Name of test file, ie `__tests__/bolt-video.e2e` */
module: testFileName,
/** @type {string} */
group,
/** @type {{ time: string, assertions: array, passed: number, errors: number, failed: number, skipped: number, tests: number, steps: array, timeMs: number}} */
results,
} = currentTest;

if (!client.launch_url.match(/saucelabs/)) {
console.log('Not saucelabs ...');
process.exit(1);
}

if (!username || !accessKey || !sessionId) {
console.log('No username, accessKey or sessionId');
console.log(username);
console.log(accessKey);
console.log(sessionId);
process.exit(1);
}

const passed = results.passed === results.tests - results.skipped;
console.log(`Passed: ${passed ? 'Yes' : 'No'} - ${name}`);

try {
const res = await fetch(
// https://wiki.saucelabs.com/display/DOCS/Job+Methods
`https://saucelabs.com/rest/v1/${SAUCE_USERNAME}/jobs/${sessionId}`,
{
method: 'PUT',
headers: {
Authorization: `Basic ${auth}`,
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
passed,
build: `build-${process.env.TRAVIS_JOB_NUMBER}`,
tags: ['CI'],
'custom-data': {
TRAVIS_JOB_NUMBER,
TRAVIS_BRANCH,
TRAVIS_PULL_REQUEST_BRANCH,
TRAVIS_PULL_REQUEST,
TRAVIS_REPO_SLUG,
TRAVIS_TAG,
TRAVIS_BUILD_WEB_URL,
gitSha,
gitShaLong,
},
}),
},
);

if (res.ok) {
// console.log(`Set SauceLabs details ok`);
} else {
console.log(`Setting SauceLabs details not ok`);
throw new Error(`Set SauceLabs details not ok ${res.statusText}`);
}

const data = JSON.stringify({
passed,
});

const requestPath = `/rest/v1/${username}/jobs/${sessionId}`;

try {
// console.log('Updating Saucelabs', requestPath);

const req = https.request(
{
hostname: 'saucelabs.com',
path: requestPath,
method: 'PUT',
auth: `${username}:${accessKey}`,
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length,
},
},
function(res) {
let results;
res.setEncoding('utf8');

if (res.statusCode !== 200) {
console.log('Failed to updating Saucelabs', requestPath);
console.log(
'Response: ',
res.statusCode,
JSON.stringify(res.headers),
);
}
res.on('data', function onData(chunk) {
// console.log('BODY: ' + chunk);
results = chunk;
});
res.on('end', function onEnd() {
console.info('Finished updating Saucelabs');
callback(results);
});
},
);

req.on('error', function onError(e) {
console.log('problem with request: ' + e.message);
});
req.write(data);
req.end();
} catch (error) {
console.log('Error', error);
callback(error);
}
} catch (err) {
console.log(`Error setting SauceLabs details`, err);
process.exit(1);
}
}

module.exports = {
handleNightwatchResults,
};
176 changes: 3 additions & 173 deletions nightwatch.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
const globby = require('globby');
const { getGitSha } = require('ci-utils');
const fetch = require('node-fetch');
const path = require('path');
const https = require('https');

const {
NOW_URL,
SAUCE_USERNAME,
SAUCE_ACCESS_KEY,
// for push builds, or builds not triggered by a pull request, this is the name of the branch.
// for builds triggered by a pull request this is the name of the branch targeted by the pull request.
// for builds triggered by a tag, this is the same as the name of the tag(TRAVIS_TAG).
TRAVIS_BRANCH,
// if the current job is a pull request, the name of the branch from which the PR originated
// if the current job is a push build, this variable is empty("").
TRAVIS_PULL_REQUEST_BRANCH,
// The pull request number if the current job is a pull request, "false" if it’s not a pull request.
TRAVIS_PULL_REQUEST,
// The slug (in form: owner_name/repo_name) of the repository currently being built.
TRAVIS_REPO_SLUG,
// If the current build is for a git tag, this variable is set to the tag’s name
TRAVIS_TAG,
TRAVIS_BUILD_WEB_URL,
TRAVIS_JOB_NUMBER,
} = process.env;

const gitSha = getGitSha(true);
const gitShaLong = getGitSha();
const { handleNightwatchResults } = require('./nightwatch.handle-results');
const { NOW_URL } = process.env;

const testingUrl = NOW_URL ? NOW_URL : 'https://boltdesignsystem.com';
// const testingUrl = 'https://boltdesignsystem.com';
console.log(`Nightwatch testingUrl is ${testingUrl}`);

const auth = Buffer.from(`${SAUCE_USERNAME}:${SAUCE_ACCESS_KEY}`).toString(
'base64',
);
console.log(`Nightwatch testingUrl is ${testingUrl}`);

let srcFolders = globby.sync([
'docs-site/**/*.e2e.js',
Expand All @@ -47,137 +18,6 @@ srcFolders = srcFolders.map(function(folder) {
return path.dirname(folder);
});

/**
* @param {Object} client - Nightwatch instance @todo add link to API docs
* @param {function} callback
* @returns {void}
*/
async function handleNightwatchResults(client, callback) {
const currentTest = client.currentTest;
const sessionId = client.capabilities['webdriver.remote.sessionid'];
const { username, accessKey } = client.options;
const {
/** @type {string} - Name of test */
name,
/** @type {string} - Name of test file, ie `__tests__/bolt-video.e2e` */
module: testFileName,
/** @type {string} */
group,
/** @type {{ time: string, assertions: array, passed: number, errors: number, failed: number, skipped: number, tests: number, steps: array, timeMs: number}} */
results,
} = currentTest;

if (!client.launch_url.match(/saucelabs/)) {
console.log('Not saucelabs ...');
process.exit(1);
}

if (!username || !accessKey || !sessionId) {
console.log('No username, accessKey or sessionId');
console.log(username);
console.log(accessKey);
console.log(sessionId);
process.exit(1);
}

const passed = results.passed === results.tests - results.skipped;
console.log(`Passed: ${passed ? 'Yes' : 'No'} - ${name}`);

try {
const res = await fetch(
// https://wiki.saucelabs.com/display/DOCS/Job+Methods
`https://saucelabs.com/rest/v1/${SAUCE_USERNAME}/jobs/${sessionId}`,
{
method: 'PUT',
headers: {
Authorization: `Basic ${auth}`,
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
passed,
build: `build-${process.env.TRAVIS_JOB_NUMBER}`,
tags: ['CI'],
'custom-data': {
TRAVIS_JOB_NUMBER,
TRAVIS_BRANCH,
TRAVIS_PULL_REQUEST_BRANCH,
TRAVIS_PULL_REQUEST,
TRAVIS_REPO_SLUG,
TRAVIS_TAG,
TRAVIS_BUILD_WEB_URL,
gitSha,
gitShaLong,
},
}),
},
);

if (res.ok) {
// console.log(`Set SauceLabs details ok`);
} else {
console.log(`Setting SauceLabs details not ok`);
throw new Error(`Set SauceLabs details not ok ${res.statusText}`);
}

const data = JSON.stringify({
passed,
});

const requestPath = `/rest/v1/${username}/jobs/${sessionId}`;

try {
// console.log('Updating Saucelabs', requestPath);

const req = https.request(
{
hostname: 'saucelabs.com',
path: requestPath,
method: 'PUT',
auth: `${username}:${accessKey}`,
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length,
},
},
function(res) {
let results;
res.setEncoding('utf8');

if (res.statusCode !== 200) {
console.log('Failed to updating Saucelabs', requestPath);
console.log(
'Response: ',
res.statusCode,
JSON.stringify(res.headers),
);
}
res.on('data', function onData(chunk) {
// console.log('BODY: ' + chunk);
results = chunk;
});
res.on('end', function onEnd() {
console.info('Finished updating Saucelabs');
callback(results);
});
},
);

req.on('error', function onError(e) {
console.log('problem with request: ' + e.message);
});
req.write(data);
req.end();
} catch (error) {
console.log('Error', error);
callback(error);
}
} catch (err) {
console.log(`Error setting SauceLabs details`, err);
process.exit(1);
}
}

module.exports = {
globals: {
asyncHookTimeout: 30000, // increasing timeout to prevent errors in Sauce Labs
Expand All @@ -200,16 +40,6 @@ module.exports = {
},
},
persist_globals: true,
// selenium: {
// start_process: true,
// server_path: require('selenium-server').path,
// log_path: './reports',
// host: '127.0.0.1',
// port: 4444,
// cli_args: {
// 'webdriver.chrome.driver': './node_modules/chromedriver/bin/chromedriver',
// },
// },
live_output: false, // set to `true` to see output as it happens; make appear interlaced if ran in parallel
test_workers: { enabled: true, workers: '1' },
test_settings: {
Expand Down
Loading