mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-06 20:11:38 +08:00
NOPRESUBMIT=true Bug: none Change-Id: If0e96e43aa13a2fa557a075975c2e7f365db930a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3258130 Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
87 lines
2.5 KiB
JavaScript
87 lines
2.5 KiB
JavaScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
/**
|
|
* @fileoverview Rule to check test definitions
|
|
* @author Tim van der Lippe
|
|
*/
|
|
'use strict';
|
|
|
|
const TEST_NAME_REGEX = /^\[crbug.com\/\d+\]/;
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
// ------------------------------------------------------------------------------
|
|
|
|
function getTextValue(node) {
|
|
if (node.type === 'Literal') {
|
|
return node.value;
|
|
}
|
|
if (node.type === 'TemplateLiteral') {
|
|
if (node.quasis.length === 0) {
|
|
return undefined;
|
|
}
|
|
return node.quasis[0].value.cooked;
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'problem',
|
|
|
|
docs: {
|
|
description: 'check test implementations',
|
|
category: 'Possible Errors',
|
|
},
|
|
messages: {
|
|
missingBugId:
|
|
'Skipped tests must have a CRBug included in the description: `it.skip(\'[crbug.com/BUGID]: testname\', async() => {})',
|
|
extraBugId:
|
|
'Non-skipped tests cannot include a CRBug tag at the beginning of the description: `it.skip(\'testname (crbug.com/BUGID)\', async() => {})',
|
|
comment: 'A skipped test must have an attached comment with an explanation written before the test'
|
|
},
|
|
fixable: 'code',
|
|
schema: [] // no options
|
|
},
|
|
create: function(context) {
|
|
return {
|
|
MemberExpression(node) {
|
|
if ((node.object.name === 'it' || node.object.name === 'describe') &&
|
|
(node.property.name === 'skip' || node.property.name === 'skipOnPlatforms') &&
|
|
node.parent.type === 'CallExpression') {
|
|
const testNameNode = node.property.name === 'skip' ? node.parent.arguments[0] : node.parent.arguments[1];
|
|
|
|
const textValue = getTextValue(testNameNode);
|
|
|
|
if (!textValue || !TEST_NAME_REGEX.test(textValue)) {
|
|
context.report({
|
|
node,
|
|
messageId: 'missingBugId',
|
|
});
|
|
}
|
|
|
|
const attachedComments = context.getCommentsBefore(node.parent);
|
|
|
|
if (attachedComments.length === 0) {
|
|
context.report({node, messageId: 'comment'});
|
|
}
|
|
}
|
|
},
|
|
|
|
CallExpression(node) {
|
|
if (node.callee.name === 'it') {
|
|
const textValue = getTextValue(node.arguments[0]);
|
|
|
|
if (textValue && TEST_NAME_REGEX.test(textValue)) {
|
|
context.report({
|
|
node,
|
|
messageId: 'extraBugId',
|
|
});
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
};
|