From 09c6b982fefbafc545bfbdaf1433111cdb04f1b3 Mon Sep 17 00:00:00 2001 From: XantreDev Date: Sat, 22 Jun 2024 18:33:54 +0200 Subject: [PATCH] e2e test no custom classnames --- tests/integrations/no-custom-classname.js | 83 +++++++++++++++++++ .../no-custom-classname/.gitignore | 2 + tests/integrations/no-custom-classname/.npmrc | 1 + .../no-custom-classname/eslint.config.js | 19 +++++ .../no-custom-classname/package.json | 13 +++ .../no-custom-classname/src/.gitkeep | 0 6 files changed, 118 insertions(+) create mode 100644 tests/integrations/no-custom-classname.js create mode 100644 tests/integrations/no-custom-classname/.gitignore create mode 100644 tests/integrations/no-custom-classname/.npmrc create mode 100644 tests/integrations/no-custom-classname/eslint.config.js create mode 100644 tests/integrations/no-custom-classname/package.json create mode 100644 tests/integrations/no-custom-classname/src/.gitkeep diff --git a/tests/integrations/no-custom-classname.js b/tests/integrations/no-custom-classname.js new file mode 100644 index 00000000..253020b7 --- /dev/null +++ b/tests/integrations/no-custom-classname.js @@ -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
+}\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); + }); +}); diff --git a/tests/integrations/no-custom-classname/.gitignore b/tests/integrations/no-custom-classname/.gitignore new file mode 100644 index 00000000..132f5b96 --- /dev/null +++ b/tests/integrations/no-custom-classname/.gitignore @@ -0,0 +1,2 @@ +src/** +!src/.gitkeep diff --git a/tests/integrations/no-custom-classname/.npmrc b/tests/integrations/no-custom-classname/.npmrc new file mode 100644 index 00000000..43c97e71 --- /dev/null +++ b/tests/integrations/no-custom-classname/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/tests/integrations/no-custom-classname/eslint.config.js b/tests/integrations/no-custom-classname/eslint.config.js new file mode 100644 index 00000000..21ed4892 --- /dev/null +++ b/tests/integrations/no-custom-classname/eslint.config.js @@ -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", + }, + }, +]; diff --git a/tests/integrations/no-custom-classname/package.json b/tests/integrations/no-custom-classname/package.json new file mode 100644 index 00000000..9cab9c7f --- /dev/null +++ b/tests/integrations/no-custom-classname/package.json @@ -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" +} diff --git a/tests/integrations/no-custom-classname/src/.gitkeep b/tests/integrations/no-custom-classname/src/.gitkeep new file mode 100644 index 00000000..e69de29b