Skip to content

Commit

Permalink
Merge pull request #87 from pulsar-edit/remove-request
Browse files Browse the repository at this point in the history
Remove `request` Migrate to `superagent` && Fix CI
  • Loading branch information
confused-Techie authored Sep 22, 2023
2 parents a2ade74 + 85fa9d3 commit c9f9da8
Show file tree
Hide file tree
Showing 16 changed files with 742 additions and 71 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ jobs:
run: ./bin/npm test
# Q: Why are we using some random test section when the package.json has a test script?
# A: So that we ensure we use the bundled version of node to run our tests
- if: failure()
name: Print Logs for exceptions
run: if [[ -f "./script/log.txt" ]]; then cat ./script/log.txt; else echo "No log file found at ./script/log.txt"; fi
shell: bash

Skip:
if: contains(github.event.head_commit.message, '[skip ci]')
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"clean:bin": "shx rm -rf bin/node_darwin_x64 bin/node.exe bin/node",
"clean": "npm run clean:bin",
"postinstall": "node script/postinstall.js",
"test": "npm run check-version && jasmine-focused --captureExceptions spec"
"test": "npm run check-version && node ./script/local-jasmine.js --captureExceptions spec"
},
"dependencies": {
"@atom/plist": "0.4.4",
Expand All @@ -42,6 +42,8 @@
"second-mate": "https://github.com/pulsar-edit/second-mate.git#9686771",
"season": "^6.0.2",
"semver": "^7.3.4",
"superagent": "^8.0.9",
"superagent-proxy": "^3.0.0",
"tar": "^6.0.5",
"temp": "^0.9.4",
"underscore-plus": "1.x",
Expand Down
279 changes: 279 additions & 0 deletions script/local-jasmine-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
var util,
Path= require('path'),
fs = require('fs');

var jasmine = require('jasmine-node/lib/jasmine-node/index');

process.on("uncaughtException", (err) => {
// Where does our logs go? I can't seem to output in any sane way at all for this
fs.writeFileSync(`${__dirname}/log.txt`, JSON.stringify(err) + "\n", { encoding: "utf8", flag: "a+"});
fs.writeFileSync(`${__dirname}/log.txt`, JSON.stringify(err.stack) + "\n", { encoding: "utf8", flag: "a+"});
});


try {
util = require('util')
} catch(e) {
util = require('sys')
}

var helperCollection = require('jasmine-node/lib/jasmine-node/spec-collection');

var specFolders = [];
var watchFolders = [];

// The following line keeps the jasmine setTimeout in the proper scope
jasmine.setTimeout = jasmine.getGlobal().setTimeout;
jasmine.setInterval = jasmine.getGlobal().setInterval;
for (var key in jasmine)
global[key] = jasmine[key];

var isVerbose = false;
var showColors = true;
var teamcity = process.env.TEAMCITY_PROJECT_NAME || false;
var useRequireJs = false;
var extentions = "js";
var match = '.';
var matchall = false;
var autotest = false;
var useHelpers = true;
var forceExit = false;
var captureExceptions = false;
var includeStackTrace = true;

var junitreport = {
report: false,
savePath : "./reports/",
useDotNotation: true,
consolidate: true
}

var args = process.argv.slice(2);
var existsSync = fs.existsSync || Path.existsSync;

while(args.length) {
var arg = args.shift();

switch(arg)
{
case '--version':
printVersion();
case '--color':
showColors = true;
break;
case '--noColor':
case '--nocolor':
showColors = false;
break;
case '--verbose':
isVerbose = true;
break;
case '--coffee':
require('coffee-script');
extentions = "js|coffee|litcoffee";
break;
case '-m':
case '--match':
match = args.shift();
break;
case '--matchall':
matchall = true;
break;
case '--junitreport':
junitreport.report = true;
break;
case '--output':
junitreport.savePath = args.shift();
break;
case '--teamcity':
teamcity = true;
break;
case '--requireJsSetup':
var setup = args.shift();

if(!existsSync(setup))
throw new Error("RequireJS setup '" + setup + "' doesn't exist!");

useRequireJs = setup;
break;
case '--runWithRequireJs':
useRequireJs = useRequireJs || true;
break;
case '--nohelpers':
useHelpers = false;
break;
case '--test-dir':
var dir = args.shift();

if(!existsSync(dir))
throw new Error("Test root path '" + dir + "' doesn't exist!");

specFolders.push(dir); // NOTE: Does not look from current working directory.
break;
case '--autotest':
autotest = true;
break;
case '--watch':
var nextWatchDir;

// Add the following arguments, until we see another argument starting with '-'
while (args[0] && args[0][0] !== '-') {
nextWatchDir = args.shift();
watchFolders.push(nextWatchDir);

if (!existsSync(nextWatchDir))
throw new Error("Watch path '" + watchDir + "' doesn't exist!");
}
break;

case '--forceexit':
forceExit = true;
break;
case '--captureExceptions':
captureExceptions = true;
break;
case '--noStack':
includeStackTrace = false;
break;
case '--config':
var configKey = args.shift();
var configValue = args.shift();
process.env[configKey]=configValue;
break;
case '-h':
help();
default:
if (arg.match(/^--params=.*/)) {
break;
}
if (arg.match(/^--/)) help();
if (arg.match(/^\/.*/)) {
specFolders.push(arg);
} else {
specFolders.push(Path.join(process.cwd(), arg));
}
break;
}
}

if (specFolders.length === 0) {
help();
} else {
// Check to see if all our files exist
for (var idx = 0; idx < specFolders.length; idx++) {
if (!existsSync(specFolders[idx])) {
console.log("File: " + specFolders[idx] + " is missing.");
return;
}
}
}

if (autotest) {

var patterns = ['**/*.js'];

if (extentions.indexOf("coffee") !== -1) {
patterns.push('**/*.coffee');
}

require('jasmine-node/lib/jasmine-node/autotest').start(specFolders, watchFolders, patterns);

return;
}

var exitCode = 0;

if (captureExceptions) {
process.on('uncaughtException', function(e) {
console.error(e.stack || e);
exitCode = 1;
process.exit(exitCode);
});
}

process.on("exit", onExit);

function onExit() {
process.removeListener("exit", onExit);
process.exit(exitCode);
}

var onComplete = function(runner, log) {
process.stdout.write('\n');
if (runner.results().failedCount == 0) {
exitCode = 0;
} else {
exitCode = 1;
}
if (forceExit) {
process.exit(exitCode);
}
};

if(useHelpers){
specFolders.forEach(function(path){
jasmine.loadHelpersInFolder(path,
new RegExp("helpers?\\.(" + extentions + ")$", 'i'));

})
}

try {
var regExpSpec = new RegExp(match + (matchall ? "" : "spec\\.") + "(" + extentions + ")$", 'i')
} catch (error) {
console.error("Failed to build spec-matching regex: " + error);
process.exit(2);
}


var options = {
specFolders: specFolders,
onComplete: onComplete,
isVerbose: isVerbose,
showColors: showColors,
teamcity: teamcity,
useRequireJs: useRequireJs,
regExpSpec: regExpSpec,
junitreport: junitreport,
includeStackTrace: includeStackTrace
}

jasmine.executeSpecsInFolder(options);


function help(){
process.stdout.write([
'USAGE: jasmine-node [--color|--noColor] [--verbose] [--coffee] directory'
, ''
, 'Options:'
, ' --autotest - rerun automatically the specs when a file changes'
, ' --watch PATH - when used with --autotest, watches the given path(s) and runs all tests if a change is detected'
, ' --color - use color coding for output'
, ' --noColor - do not use color coding for output'
, ' -m, --match REGEXP - load only specs containing "REGEXPspec"'
, ' --matchall - relax requirement of "spec" in spec file names'
, ' --verbose - print extra information per each test run'
, ' --coffee - load coffee-script which allows execution .coffee files'
, ' --junitreport - export tests results as junitreport xml format'
, ' --output - defines the output folder for junitreport files'
, ' --teamcity - converts all console output to teamcity custom test runner commands. (Normally auto detected.)'
, ' --runWithRequireJs - loads all specs using requirejs instead of node\'s native require method'
, ' --requireJsSetup - file run before specs to include and configure RequireJS'
, ' --test-dir - the absolute root directory path where tests are located'
, ' --nohelpers - does not load helpers.'
, ' --forceexit - force exit once tests complete.'
, ' --captureExceptions- listen to global exceptions, report them and exit (interferes with Domains)'
, ' --config NAME VALUE- set a global variable in process.env'
, ' --noStack - suppress the stack trace generated from a test failure'
, ' --version - show the current version'
, ' -h, --help - display this help and exit'
, ''
].join("\n"));

process.exit(-1);
}

function printVersion(){
console.log("1.10.2");
process.exit(0);
}
4 changes: 4 additions & 0 deletions script/local-jasmine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

require("jasmine-focused");
require("./local-jasmine-node.js");
2 changes: 1 addition & 1 deletion src/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cmd-shift-o to run the package out of the newly cloned repository.\
return callback(`No repository URL found for package: ${packageName}`);
}
} else {
const message = request.getErrorMessage(response, body);
const message = request.getErrorMessage(error);
return callback(`Request for package information failed: ${message}`);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/featured.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ List the Pulsar packages and themes that are currently featured.\
packages = _.sortBy(packages, 'name');
return callback(null, packages);
} else {
const message = request.getErrorMessage(response, body);
const message = request.getErrorMessage(error);
return callback(`Requesting packages failed: ${message}`);
}
});
Expand Down
5 changes: 2 additions & 3 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ Run ppm -v after installing Git to see what version has been detected.\
if (body == null) { body = {}; }
if (error != null) {
message = `Request for package information failed: ${error.message}`;
if (error.code) { message += ` (${error.code})`; }
if (error.status) { message += ` (${error.status})`; }
return callback(message);
} else if (response.statusCode !== 200) {
message = request.getErrorMessage(response, body);
message = request.getErrorMessage(error);
return callback(`Request for package information failed: ${message}`);
} else {
if (body.releases.latest) {
Expand Down Expand Up @@ -697,7 +697,6 @@ Run ppm -v after installing Git to see what version has been detected.\

this.verbose = options.argv.verbose;
if (this.verbose) {
request.debug(true);
process.env.NODE_DEBUG = 'request';
}

Expand Down
4 changes: 2 additions & 2 deletions src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ have published it.\
if (error != null) {
return callback(error);
} else if (response.statusCode !== 201) {
const message = request.getErrorMessage(response, body);
const message = request.getErrorMessage(error);
this.logFailure();
return callback(`Registering package in ${repository} repository failed: ${message}`);
} else {
Expand Down Expand Up @@ -237,7 +237,7 @@ have published it.\
if (error != null) {
return callback(error);
} else if (response.statusCode !== 201) {
const message = request.getErrorMessage(response, body);
const message = request.getErrorMessage(error);
return callback(`Creating new version failed: ${message}`);
} else {
return callback();
Expand Down
Loading

0 comments on commit c9f9da8

Please sign in to comment.