From ff63b84489480751141c67f32570a24a9c4aaa28 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 9 Mar 2021 19:22:17 +0300 Subject: [PATCH] add a test for the transition suppressor rule --- package.json | 4 ++-- tools/test.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tools/test.js diff --git a/package.json b/package.json index 3053651d..73886a86 100644 --- a/package.json +++ b/package.json @@ -28,11 +28,11 @@ }, "scripts": { "lint": "eslint \"**/*.js\" --cache", - "test": "npm run lint", + "test": "node tools/test.js && npm run lint", "update-locales": "tx pull --all && node tools/fix-transifex.js", "update-transifex": "tx push -s", "build-vendor": "node tools/build-vendor", - "zip": "node tools/zip.js", + "zip": "npm test && node tools/zip.js", "start": "web-ext run", "start-chrome": "web-ext run -t chromium", "preversion": "npm test", diff --git a/tools/test.js b/tools/test.js new file mode 100644 index 00000000..0134ac58 --- /dev/null +++ b/tools/test.js @@ -0,0 +1,16 @@ +'use strict'; + +const fs = require('fs'); + +testGlobalCss(); + +function testGlobalCss() { + const css = fs.readFileSync('global.css', {encoding: 'utf8'}); + const ERR = 'global.css: the first rule must be the transition suppressor'; + const RX_SUPPRESSOR = /^[^{}]+{\s*transition:\s*none\s*!\s*important/i; + const RX_COMMENT = /\/\*([^*]|\*(?!\/))*(\*\/|$)/g; + if (!RX_SUPPRESSOR.test(css.replace(RX_COMMENT, ''))) { + console.error(ERR); + process.exit(1); + } +}