Skip to content
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
20 changes: 15 additions & 5 deletions test/lib/InputProcessor.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {InputProcessor, InputProcessorImpl} from "../../src/lib/InputProcessor";
import {assert, expect} from "chai";
import {expect} from "chai";
import * as path from "path";
import {Inputs} from "../../src/types";
import {BundleName, getMessage} from "../../src/MessageCatalog";
Expand Down Expand Up @@ -129,24 +129,34 @@ describe("InputProcessorImpl Tests", async () => {
const inputs: Inputs = {
target: ['thisFileDoesNotExist.xml', 'thisFileAlsoDoesNotExist.json']
};
let errorThrown: boolean;
let message: string;
try {
inputProcessor.resolveProjectDirPaths(inputs);
assert.fail("Expected error to be thrown")
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.CommonRun, 'validations.noFilesFoundInTarget'));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should have been thrown');
expect(message).to.equal(getMessage(BundleName.CommonRun, 'validations.noFilesFoundInTarget'));
})

it("Unspecified projectdir with glob target that resolves to no files", async () => {
const inputs: Inputs = {
target: ['**.filesOfThisTypeShouldNotExist']
};
let errorThrown: boolean;
let message: string;
try {
inputProcessor.resolveProjectDirPaths(inputs);
assert.fail("Expected error to be thrown")
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.CommonRun, 'validations.noFilesFoundInTarget'));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should have been thrown');
expect(message).to.equal(getMessage(BundleName.CommonRun, 'validations.noFilesFoundInTarget'));
})
})
})
Expand Down
26 changes: 19 additions & 7 deletions test/lib/JreSetupManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assert, expect} from 'chai';
import {expect} from 'chai';
import {FileHandler} from '../../src/lib/util/FileHandler';
import {Config} from '../../src/lib/util/Config';
import Sinon = require('sinon');
Expand Down Expand Up @@ -196,13 +196,19 @@ describe('JreSetupManager #verifyJreSetup', () => {
const statStub = Sinon.stub(FileHandler.prototype, 'stats').throws(error);

// Execute and verify
let errorThrown: boolean;
let errName: string;
try {
await verifyJreSetup();
assert.fail('Should have failed');
errorThrown = false;
} catch (err) {
expect(err.name).equals('InvalidJavaHome');
expect(uniqueWarningCounter).to.equal(0);
errorThrown = true;
errName = err.name;
}
expect(errorThrown).to.equal(true, 'Should have failed');
expect(errName).equals('InvalidJavaHome');
expect(uniqueWarningCounter).to.equal(0);


configGetJavaHomeStub.restore();
statStub.restore();
Expand All @@ -216,13 +222,19 @@ describe('JreSetupManager #verifyJreSetup', () => {
const execStub = Sinon.stub(childProcess, 'execFile').yields(noError, emptyStdout, invalidVersion);

// Execute and verify
let errorThrown: boolean;
let errName: string;
try {
await verifyJreSetup();
assert.fail('Should have failed');
errorThrown = false;
} catch (err) {
expect(err.name).equals('InvalidVersion');
expect(uniqueWarningCounter).to.equal(0);
errorThrown = true;
errName = err.name;
}
expect(errorThrown).to.equal(true, 'Should have failed');
expect(errName).equals('InvalidVersion');
expect(uniqueWarningCounter).to.equal(0);


configGetJavaHomeStub.restore();
statStub.restore();
Expand Down
47 changes: 36 additions & 11 deletions test/lib/actions/RuleAddAction.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Logger} from '@salesforce/core';
import {assert, expect} from 'chai';
import {expect} from 'chai';
import sinon = require('sinon');
import path = require('path');
import untildify = require('untildify');
Expand Down Expand Up @@ -68,12 +68,17 @@ describe('RuleAddAction', () => {
path: ['this/does/not/matter']
};

let errorThrown: boolean;
let message: string;
try {
await testAction.validateInputs(inputs);
assert.fail('Exception should have been thrown');
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.Add, 'validations.languageCannotBeEmpty', []));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should be thrown');
expect(message).to.equal(getMessage(BundleName.Add, 'validations.languageCannotBeEmpty', []));
});

it('Rejects empty `.language` property', async () => {
Expand All @@ -82,25 +87,35 @@ describe('RuleAddAction', () => {
path: ['this/does/not/matter']
};

let errorThrown: boolean;
let message: string;
try {
await testAction.validateInputs(inputs);
assert.fail('Exception should have been thrown');
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.Add, 'validations.languageCannotBeEmpty', []));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should be thrown');
expect(message).to.equal(getMessage(BundleName.Add, 'validations.languageCannotBeEmpty', []));
});

it('Rejects missing `.path` property', async () => {
const inputs: Inputs = {
language: 'apex'
};

let errorThrown: boolean;
let message: string;
try {
await testAction.validateInputs(inputs);
assert.fail('Exception should have been thrown');
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.Add, 'validations.pathCannotBeEmpty', []));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should be thrown');
expect(message).to.equal(getMessage(BundleName.Add, 'validations.pathCannotBeEmpty', []));
});

it('Rejects empty `.path` property', async () => {
Expand All @@ -109,12 +124,17 @@ describe('RuleAddAction', () => {
path: []
};

let errorThrown: boolean;
let message: string;
try {
await testAction.validateInputs(inputs);
assert.fail('Exception should have been thrown');
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.Add, 'validations.pathCannotBeEmpty', []));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should be thrown');
expect(message).to.equal(getMessage(BundleName.Add, 'validations.pathCannotBeEmpty', []));
});

it('Rejects `.path` containing empty string', async () => {
Expand All @@ -123,12 +143,17 @@ describe('RuleAddAction', () => {
path: [""]
}

let errorThrown: boolean;
let message: string;
try {
await testAction.validateInputs(inputs);
assert.fail('Exception should have been thrown');
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.Add, 'validations.pathCannotBeEmpty', []));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should be thrown');
expect(message).to.equal(getMessage(BundleName.Add, 'validations.pathCannotBeEmpty', []));
});
});

Expand Down
50 changes: 38 additions & 12 deletions test/lib/actions/RuleRemoveAction.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Logger} from '@salesforce/core';
import {assert, expect} from 'chai';
import {expect} from 'chai';
import {FileHandler} from '../../../src/lib/util/FileHandler';
import sinon = require('sinon');
import path = require('path');
Expand Down Expand Up @@ -34,25 +34,35 @@ describe('RuleRemoveAction', () => {
path: []
};

let errorThrown: boolean;
let message: string;
try {
await testAction.validateInputs(inputs);
assert.fail('Exception should have been thrown');
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.Remove, 'validations.pathCannotBeEmpty', []));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should have been thrown');
expect(message).to.equal(getMessage(BundleName.Remove, 'validations.pathCannotBeEmpty', []));
});

it('rejects `.path` containing empty string', async () => {
const inputs: Inputs = {
path: ['']
};

let errorThrown: boolean;
let message: string;
try {
await testAction.validateInputs(inputs);
assert.fail('Exception should have been thrown');
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.Remove, 'validations.pathCannotBeEmpty', []));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should have been thrown');
expect(message).to.equal(getMessage(BundleName.Remove, 'validations.pathCannotBeEmpty', []));
});
});

Expand Down Expand Up @@ -97,13 +107,19 @@ describe('RuleRemoveAction', () => {
const inputs: Inputs = {
path: [FAKE_PATH_1]
};
let errorThrown: boolean;
let message: string;
try {
await testAction.run(inputs);
assert.fail('Error should have been thrown');
errorThrown = false;
} catch (e) {
// ==== ASSERTIONS ====
expect(e.message).to.equal(getMessage(BundleName.Remove, 'errors.noMatchingPaths'));
errorThrown = true;
message = e.message;
}

// ==== ASSERTIONS ====
expect(errorThrown).to.equal(true, 'Error should have been thrown');
expect(message).to.equal(getMessage(BundleName.Remove, 'errors.noMatchingPaths'));
});
});

Expand Down Expand Up @@ -188,12 +204,17 @@ describe('RuleRemoveAction', () => {
const inputs = {
path: [FAKE_PATH_4]
};
let errorThrown: boolean;
let message: string;
try {
await testAction.run(inputs);
assert.fail('Error should have thrown');
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.Remove, 'errors.noMatchingPaths', []));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should have been thrown');
expect(message).to.equal(getMessage(BundleName.Remove, 'errors.noMatchingPaths', []));
});

it('Test Case: Action can be aborted during confirmation prompt', async () => {
Expand Down Expand Up @@ -246,12 +267,17 @@ describe('RuleRemoveAction', () => {
path: [FAKE_PATH_4],
force: true
};
let errorThrown: boolean;
let message: string;
try {
await testAction.run(inputs);
assert.fail('Error should have thrown');
errorThrown = false;
} catch (e) {
expect(e.message).to.equal(getMessage(BundleName.Remove, 'errors.noMatchingPaths', []));
errorThrown = true;
message = e.message;
}
expect(errorThrown).to.equal(true, 'Error should have been thrown');
expect(message).to.equal(getMessage(BundleName.Remove, 'errors.noMatchingPaths', []));
});
});
});
Expand Down
Loading