Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Improve error message for unsupported environments #1491

Merged
merged 1 commit into from
Apr 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 23 additions & 10 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,42 @@ function getHumanNodeVersion(arg) {
}

function getHumanEnvironment(env) {
var parts = env.replace(/_binding\.node$/, '').split('-');
var binding = env.replace(/_binding\.node$/, ''),
parts = binding.split('-'),
platform = getHumanPlatform(parts[0]),
arch = getHumanArchitecture(parts[1]),
runtime = getHumanNodeVersion(parts[2]);

if (parts.length !== 3) {
return 'Unknown environment';
return 'Unknown environment (' + binding + ')';
}

if (!platform) {
platform = 'Unsupported platform (' + parts[0] + ')';
}

if (!arch) {
arch = 'Unsupported architecture (' + parts[1] + ')';
}

if (!runtime) {
runtime = 'Unsupported runtime (' + parts[2] + ')';
}

return [
getHumanPlatform(parts[0]),
getHumanArchitecture(parts[1]),
'with',
getHumanNodeVersion(parts[2]),
platform, arch, 'with', runtime,
].join(' ');
}

function getInstalledBinaries() {
return fs.readdirSync(defaultBinaryPath);
}

function isSupportedEnvironment() {
function isSupportedEnvironment(platform, arch, runtime) {
return (
false !== getHumanPlatform() &&
false !== getHumanArchitecture() &&
false !== getHumanNodeVersion()
false !== getHumanPlatform(platform) &&
false !== getHumanArchitecture(arch) &&
false !== getHumanNodeVersion(runtime)
);
}

Expand Down
99 changes: 72 additions & 27 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1829,49 +1829,94 @@ describe('api', function() {
});

describe('on unsupported environment', function() {
it('should error for unsupported architecture', function() {
var prevValue = process.arch;
describe('with an unsupported architecture', function() {
var prevValue;

Object.defineProperty(process, 'arch', {
get: function () { return 'foo'; }
beforeEach(function() {
prevValue = process.arch;

Object.defineProperty(process, 'arch', {
get: function () { return 'foo'; }
});
});

assert.throws(
function() { require(sassPath); },
'Node Sass does not yet support your current environment'
);
afterEach(function() {
process.arch = prevValue;
});

it('should error', function() {
assert.throws(
function() { require(sassPath); },
'Node Sass does not yet support your current environment'
);
});

process.arch = prevValue;
it('should inform the user the architecture is unsupported', function() {
assert.throws(
function() { require(sassPath); },
'Unsupported architecture (foo)'
);
});
});

it('should error for unsupported platform', function() {
var prevValue = process.platform;
describe.only('with an unsupported platform', function() {
var prevValue;

Object.defineProperty(process, 'platform', {
get: function () { return 'foo'; }
beforeEach(function() {
prevValue = process.platform;

Object.defineProperty(process, 'platform', {
get: function () { return 'bar'; }
});
});

assert.throws(
function() { require(sassPath); },
'Node Sass does not yet support your current environment'
);
afterEach(function() {
process.platform = prevValue;
});

it('should error', function() {
assert.throws(
function() { require(sassPath); },
'Node Sass does not yet support your current environment'
);
});

process.platform = prevValue;
it('should inform the user the platform is unsupported', function() {
assert.throws(
function() { require(sassPath); },
'Unsupported platform (bar)'
);
});
});

it('should error for unsupported runtime', function() {
var prevValue = process.versions.modules;
describe('with an unsupported platform', function() {
var prevValue;

Object.defineProperty(process.versions, 'modules', {
get: function () { return 'foo'; }
beforeEach(function() {
prevValue = process.versions.modules;

Object.defineProperty(process.versions, 'modules', {
get: function () { return 'baz'; }
});
});

assert.throws(
function() { require(sassPath); },
'Node Sass does not yet support your current environment'
);
afterEach(function() {
process.versions.modules = prevValue;
});

process.versions.modules = prevValue;
it('should error', function() {
assert.throws(
function() { require(sassPath); },
'Node Sass does not yet support your current environment'
);
});

it('should inform the user the runtime is unsupported', function() {
assert.throws(
function() { require(sassPath); },
'Unsupported runtime (baz)'
);
});
});
});
});
Expand Down