mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
69 lines
1.4 KiB
JavaScript
69 lines
1.4 KiB
JavaScript
|
"use strict";
|
|||
|
|
|||
|
Object.defineProperty(exports, "__esModule", {
|
|||
|
value: true
|
|||
|
});
|
|||
|
exports.default = void 0;
|
|||
|
|
|||
|
var _utils = require("./utils");
|
|||
|
|
|||
|
var _default = (0, _utils.createRule)({
|
|||
|
name: __filename,
|
|||
|
meta: {
|
|||
|
docs: {
|
|||
|
description: 'Prefer using toThrow for exception tests',
|
|||
|
category: 'Best Practices',
|
|||
|
recommended: false
|
|||
|
},
|
|||
|
messages: {
|
|||
|
noTryExpect: ['Tests should use Jest‘s exception helpers.', 'Use "expect(() => yourFunction()).toThrow()" for synchronous tests,', 'or "await expect(yourFunction()).rejects.toThrow()" for async tests'].join(' ')
|
|||
|
},
|
|||
|
type: 'problem',
|
|||
|
schema: []
|
|||
|
},
|
|||
|
defaultOptions: [],
|
|||
|
|
|||
|
create(context) {
|
|||
|
let isTest = false;
|
|||
|
let catchDepth = 0;
|
|||
|
|
|||
|
function isThrowExpectCall(node) {
|
|||
|
return catchDepth > 0 && (0, _utils.isExpectCall)(node);
|
|||
|
}
|
|||
|
|
|||
|
return {
|
|||
|
CallExpression(node) {
|
|||
|
if ((0, _utils.isTestCase)(node)) {
|
|||
|
isTest = true;
|
|||
|
} else if (isTest && isThrowExpectCall(node)) {
|
|||
|
context.report({
|
|||
|
messageId: 'noTryExpect',
|
|||
|
node
|
|||
|
});
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
CatchClause() {
|
|||
|
if (isTest) {
|
|||
|
++catchDepth;
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
'CatchClause:exit'() {
|
|||
|
if (isTest) {
|
|||
|
--catchDepth;
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
'CallExpression:exit'(node) {
|
|||
|
if ((0, _utils.isTestCase)(node)) {
|
|||
|
isTest = false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
});
|
|||
|
|
|||
|
exports.default = _default;
|