test: enable a few jest eslint rules (#6900)

* test: enable a few jest eslint rules

* more
This commit is contained in:
Joshua Chen 2022-03-12 08:43:09 +08:00 committed by GitHub
parent 1efc6c6091
commit aa5a2d4c04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
155 changed files with 3644 additions and 3478 deletions

View file

@ -45,55 +45,53 @@ expect.extend({
},
});
describe('users', () => {
sortedUsers.forEach((user) => {
test(user.title, async () => {
Joi.attempt(
user,
Joi.object<User>({
title: Joi.string().required(),
description: Joi.string().required(),
website: Joi.string()
.pattern(/^https?:\/\//)
.message('')
.required(),
// The preview should be jest/emptyModule
preview: Joi.object({}).unknown(false).required().messages({
'object.base':
'The image should be hosted on Docusaurus site, and not use remote HTTP or HTTPS URLs. It must be imported with require().',
}),
tags: Joi.array()
.items(...TagList)
.required(),
source: Joi.string().allow(null).required().messages({
'any.required':
"The source attribute is required.\nIf your Docusaurus site is not open-source, please make it explicit with 'source: null'.",
}),
}).unknown(false),
describe('users data', () => {
it.each(sortedUsers)('$title', async (user) => {
Joi.attempt(
user,
Joi.object<User>({
title: Joi.string().required(),
description: Joi.string().required(),
website: Joi.string()
.pattern(/^https?:\/\//)
.message('')
.required(),
// The preview should be jest/emptyModule
preview: Joi.object({}).unknown(false).required().messages({
'object.base':
'The image should be hosted on Docusaurus site, and not use remote HTTP or HTTPS URLs. It must be imported with require().',
}),
tags: Joi.array()
.items(...TagList)
.required(),
source: Joi.string().allow(null).required().messages({
'any.required':
"The source attribute is required.\nIf your Docusaurus site is not open-source, please make it explicit with 'source: null'.",
}),
}).unknown(false),
);
if (user.tags.includes('opensource') && user.source === null) {
throw new Error(
"You can't add the 'opensource' tag to a site that does not have a link to source code. Please add your source code, or remove this tag.",
);
if (user.tags.includes('opensource') && user.source === null) {
throw new Error(
"You can't add the 'opensource' tag to a site that does not have a link to source code. Please add your source code, or remove this tag.",
);
} else if (user.source !== null && !user.tags.includes('opensource')) {
throw new Error(
"For open-source sites, please add the 'opensource' tag.",
);
}
});
} else if (user.source !== null && !user.tags.includes('opensource')) {
throw new Error(
"For open-source sites, please add the 'opensource' tag.",
);
}
});
});
describe('preview images', () => {
const imageDir = path.join(__dirname, '../showcase');
// eslint-disable-next-line no-restricted-properties
const files = fs
.readdirSync(imageDir)
.filter((file) => ['.png', 'jpg', '.jpeg'].includes(path.extname(file)));
files.forEach((file) => {
test(file, () => {
const size = imageSize(path.join(imageDir, file));
it.each(files)('%s', (file) => {
const size = imageSize(path.join(imageDir, file));
expect(size).toHaveGoodDimensions();
});
expect(size).toHaveGoodDimensions();
});
});