Skip to content

Commit

Permalink
🔥 remove obsolete request pkg, replace obsolete wd pkg with webdriver…
Browse files Browse the repository at this point in the history
…, remove package-lock
  • Loading branch information
ctcpip committed Jun 26, 2024
1 parent 59e2495 commit 7684d21
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 1,241 deletions.
59 changes: 51 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,67 @@ on:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
node: [8, 10]
name:
- Node 8
- Node 10
- Node 12
- Node 14
- Node 16
- Node 18
- Node 20
- Node 22

include:
- name: Node 8
node-version: 8
npm-i: mocha@7.2.0

- name: Node 10
node-version: 10
npm-i: mocha@8.4.0

- name: Node 12
node-version: 12"
npm-i: mocha@9.2.2

- name: Node 14
node-version: 14

- name: Node 16
node-version: 16

- name: Node 18
node-version: 18

- name: Node 20
node-version: 20

- name: Node 22
node-version: 22

max-parallel: 1
fail-fast: true

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: package.json

- run: npm i

- run: npm install --save-dev ${{ matrix.npm-i }}
if: matrix.npm-i != ''

- run: npm test
env:
SAUCE_USERNAME: ember-cli-sauce-ci
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
39 changes: 23 additions & 16 deletions lib/remote-browser.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
/**
* JavaScript tests integration with Sauce
* https://saucelabs.com/docs/javascript-unit-tests-integration
*/
var webdriver = require('wd');
var { remote } = require('webdriver');
var Bluebird = require('bluebird');

module.exports = function(desired, auth, url) {
var browser = webdriver.remote("ondemand.saucelabs.com", 80, auth.username, auth.accessKey);
var initAsync = Bluebird.promisify(browser.init, { context: browser });
module.exports = function(config, url) {
var desiredCapabilities = config.desired();
var auth = config.auth();
var username = auth.username;
var accessKey = auth.accessKey;

var browser = remote({
hostname: 'ondemand.saucelabs.com',
port: 80,
path: '/wd/hub',
capabilities: desiredCapabilities,
user: username,
key: accessKey
});

var initAsync = Bluebird.promisify(browser.init.bind(browser));

var pendingHeartBeat;
var heartbeat = function() {
pendingHeartBeat = setTimeout(function() {
browser.title();
pendingHeartBeat = setTimeout(async function() {
await browser.getTitle();
heartbeat();
}, 60000);
};

return initAsync(desired).then(function () {
console.log("# Created remote browser.");

return initAsync().then(function () {
heartbeat();

var getAsync = Bluebird.promisify(browser.get, { context: browser });
var getAsync = Bluebird.promisify(browser.url.bind(browser));

return getAsync(url).then(function () {
return browser;
});
}).disposer(function() {
clearTimeout(pendingHeartBeat);

var quitAsync = Bluebird.promisify(browser.quit, { context: browser });
var quitAsync = Bluebird.promisify(browser.deleteSession.bind(browser));

return quitAsync().then(function () {
console.log("# Closed remote browser.");
console.log("Closed browser.");
});
});
};
46 changes: 34 additions & 12 deletions lib/update-job-status.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
var Bluebird = require('bluebird');
var request = require("request");

var requestAsync = Bluebird.promisify(request);
var https = require('https');

module.exports = function (sessionID, auth, data) {
var url = ["/v1/", auth.username, "/jobs/", sessionID].join("");
return new Promise((resolve, reject) => {
var options = {
hostname: 'saucelabs.com',
port: 443,
path: `/rest/v1/${auth.username}/jobs/${sessionID}`,
method: 'PUT',
auth: `${auth.username}:${auth.accessKey}`,
headers: {
'Content-Type': 'application/json'
}
};

var req = https.request(options, res => {
var body = '';

res.on('data', (chunk) => {
body += chunk;
});

res.on('end', () => {
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(JSON.parse(body));
} else {
reject(new Error(`Request failed with status code ${res.statusCode}: ${body}`));
}
});
});

req.on('error', err => {
reject(err);
});

return requestAsync({
method: "PUT",
uri: ["https://", auth.username, ":", auth.accessKey, "@saucelabs.com/rest", url].join(""),
json: true,
body: data
}).then(function (response) {
return response.body;
req.write(JSON.stringify(data));
req.end();
});
};
Loading

0 comments on commit 7684d21

Please sign in to comment.