Skip to content

Commit

Permalink
chore: fail test suite if node encounters unhandled promise rejection (
Browse files Browse the repository at this point in the history
  • Loading branch information
karanbirsingh committed Jan 14, 2022
1 parent caf52a2 commit 477a147
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"start:unified": "electron drop/electron/unified-dev/product/bundle/main.bundle.js",
"start:unified:dev": "cross-env DEV_MODE=true yarnpkg start:unified",
"start:unified:mock-adb": "cross-env ANDROID_HOME=drop/mock-adb yarnpkg start:unified",
"test": "cross-env --max-old-space-size=16384 jest --projects src/tests/unit",
"test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict' --max-old-space-size=16384 jest --projects src/tests/unit",
"publish-code-coverage": "npx codecov",
"test:e2e": "cross-env --max-old-space-size=16384 jest --projects src/tests/end-to-end --runInBand --forceExit --detectOpenHandles",
"test:e2e:docker:build": "docker build -t accessibility-insights-e2e --target web .",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe('InjectorControllerTest', () => {
validator.verifyAll();

validator.resetVerify();
validator.setupVerifyInjectionCompletedActionCalled(tabId);
await validator.invokeInjectedPromise();
validator.verifyAll();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { ScopingInputTypes } from 'background/scoping-input-types';
import { ScopingStore } from 'background/stores/global/scoping-store';
import { ScanIncompleteWarningDetector } from 'injected/scan-incomplete-warning-detector';
import { isEqual } from 'lodash';
import { clone, isFunction } from 'lodash';
import { failTestOnErrorLogger } from 'tests/unit/common/fail-test-on-error-logger';
import { IMock, It, Mock, MockBehavior, Times } from 'typemoq';
Expand Down Expand Up @@ -142,40 +143,58 @@ describe('BatchedRuleAnalyzer', () => {
scanResultsTwo,
);

const testSubjects = [testSubjectOne, testSubjectTwo];

testSubjects.forEach((testSubject, index) => {
[testSubjectOne, testSubjectTwo].forEach(testSubject => {
dateMock.reset();
dateMock
.setup(mock => mock.getTime())
.returns(_ => startTime)
.verifiable();

testSubject.analyze();
});

/*
BatchedRuleAnalyzer maintains a static list of
RuleAnalyzerConfigurations. After scanning, it
sends a scanCompleted message for each rule-config.
Because we instantiate two analyzers, each analyzer
has two configs and therefore the scanCallback
produces two scanCompleted messages.
*/
const actualMessages = [];
const expectedMessages = [
firstExpectedMessage,
secondExpectedMessage,
firstExpectedMessage,
secondExpectedMessage,
];

sendMessageMock
.setup(sm => sm(It.isAny()))
.callback(msg => {
actualMessages.push(msg);
if (isEqual(expectedMessages, actualMessages)) {
done();
}
})
.verifiable(Times.exactly(4));

scanCallbacks.forEach(callback => {
dateMock.reset();
dateMock
.setup(mock => mock.getTime())
.returns(_ => endTime)
.verifiable();

sendMessageMock.reset();
sendMessageMock.setup(sm => sm(It.isValue(firstExpectedMessage))).verifiable();

sendMessageMock
.setup(sm => sm(It.isValue(secondExpectedMessage)))
.returns(() => {
sendMessageMock.verifyAll();
if (index + 1 === testSubjects.length) {
done();
}
})
.verifiable();

scanCallbacks[index](completeRuleResults);
callback(completeRuleResults);
});
}

afterEach(() => {
sendMessageMock.verifyAll();
});

function setupProcessingMocks(
resultProcessorMock: IMock<
(results: ScanResults) => DictionaryStringTo<HtmlElementAxeResults>
Expand Down

0 comments on commit 477a147

Please sign in to comment.