Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e test no custom classnames #347

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
83 changes: 83 additions & 0 deletions tests/integrations/no-custom-classname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"use strict";

const { strict: assert } = require("assert");
const cp = require("child_process");
const { glob } = require("fast-glob");
const { writeFile, rm } = require("fs/promises");
const path = require("path");
const semver = require("semver");

const ESLINT = `.${path.sep}node_modules${path.sep}.bin${path.sep}eslint`;

const generateClassName = () => "." + Math.random().toString(16).slice(2);

const randomElement = (arr) => {
let index = Math.max(0, Math.ceil((arr.length - 1) * Math.random()));

return arr[index];
};

describe("Performace test of no-custom-classname", () => {
let originalCwd;

const FILES_TO_BE_CREATED = 80;

before(async () => {
const promises = [];
const firstClasses = [];
const files = await glob("./no-custom-classname/src/*", {
cwd: __dirname,
});
await Promise.all(files.map((file) => rm(path.resolve(__dirname, file))));

for (let i = 0; i < FILES_TO_BE_CREATED; ++i) {
let file = "";
for (let j = 0; j < 100; ++j) {
const curClass = generateClassName();
file += curClass + "{}\n";
firstClasses.push(curClass);
}
promises.push(writeFile(path.resolve(__dirname, `./no-custom-classname/src/css-${i}.css`), file, "utf-8"));
}
for (let i = 0; i < FILES_TO_BE_CREATED; ++i) {
let file = "";
for (let j = 0; j < 100; ++j) {
file += `\
const Component${j} = () => {
return <div className="mt-4 mb-5 ${randomElement(firstClasses).slice(1)}" />
}\n`;
}

promises.push(writeFile(path.resolve(__dirname, `./no-custom-classname/src/component-${i}.jsx`), file, "utf-8"));
}
originalCwd = process.cwd();
process.chdir(path.join(__dirname, "no-custom-classname"));
cp.execSync("npm i -f", { stdio: "inherit" });

await Promise.all(promises);
});
after(() => {
process.chdir(originalCwd);
});

it("performance large repo", () => {
if (
!semver.satisfies(
process.version,
require(path.join(__dirname, "no-custom-classname/node_modules/eslint/package.json")).engines.node
)
) {
return;
}

const result = JSON.parse(
cp.execSync(`${ESLINT} ./src --format=json`, {
encoding: "utf8",
})
);

assert.strictEqual(result.length, FILES_TO_BE_CREATED);
const issues = result.reduce((acc, { errorCount }) => acc + errorCount, 0);
assert.strictEqual(issues, 0);
});
});
2 changes: 2 additions & 0 deletions tests/integrations/no-custom-classname/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/**
!src/.gitkeep
1 change: 1 addition & 0 deletions tests/integrations/no-custom-classname/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
19 changes: 19 additions & 0 deletions tests/integrations/no-custom-classname/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import tailwind from "eslint-plugin-tailwindcss";

export default [
...tailwind.configs["flat/recommended"],
{
files: ["**/*.jsx"],
rules: {
"tailwindcss/classnames-order": "off",
"tailwindcss/enforces-negative-arbitrary-values": "off",
"tailwindcss/enforces-shorthand": "off",
"tailwindcss/migration-from-tailwind-2": "off",
"tailwindcss/no-arbitrary-value": "off",
"tailwindcss/no-contradicting-classname": "off",
"tailwindcss/no-unnecessary-arbitrary-value": "off",

"tailwindcss/no-custom-classname": "error",
},
},
];
13 changes: 13 additions & 0 deletions tests/integrations/no-custom-classname/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "integration-test-no-custom-classname",
"version": "1.0.0",
"description": "Integration test to check how no-custom-classname performs",
"main": "index.js",
"type": "module",
"dependencies": {
"eslint": "^8.57.0",
"eslint-plugin-tailwindcss": "file:../../.."
},
"author": "",
"license": "ISC"
}
Empty file.