Browse Source

Add fuzzing tests (#3789)

Zihua Li 1 year ago
parent
commit
8fa962db17

+ 21 - 0
.github/workflows/_fuzz.yml

@@ -0,0 +1,21 @@
+name: Unit Tests
+on:
+  workflow_call:
+jobs:
+  test:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Git checkout
+        uses: actions/checkout@v3
+
+      - name: Use Node.js
+        uses: actions/setup-node@v3
+        with:
+          node-version: 16
+          cache: npm
+
+      - run: npm ci
+        env:
+          PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1
+      - run: npm run test:fuzz

+ 1 - 2
.github/workflows/_unit.yml

@@ -32,7 +32,6 @@ jobs:
         env:
           PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1
       - run: npm run lint
-      - run: npm run test:unit:ci
+      - run: npm run test:unit
         env:
           BROWSER: ${{ matrix.browser }}
-      - run: npm run test:random

+ 2 - 0
.github/workflows/main.yml

@@ -11,5 +11,7 @@ concurrency:
 jobs:
   unit:
     uses: ./.github/workflows/_unit.yml
+  fuzz:
+    uses: ./.github/workflows/_fuzz.yml
   e2e:
     uses: ./.github/workflows/_e2e.yml

+ 5 - 1
.gitignore

@@ -19,7 +19,11 @@ formats/*.js
 modules/*.js
 themes/*.js
 ui/*.js
-test/random.js
+
+test/**/*.js
+!test/helpers/**/*.js
+!test/unit/**/*.js
+!test/unit.js
 
 core.js
 quill.js

+ 13 - 0
_develop/karma.fuzz.config.js

@@ -0,0 +1,13 @@
+const dns = require('node:dns');
+dns.setDefaultResultOrder('ipv4first');
+
+module.exports = config => {
+  config.set({
+    basePath: '../',
+    urlRoot: '/karma/',
+    files: [{ pattern: 'dist/fuzz.js', nocache: true }],
+    frameworks: ['jasmine'],
+    reporters: ['progress'],
+    browsers: ['jsdom'],
+  });
+};

+ 1 - 0
_develop/karma.config.js → _develop/karma.unit.config.js

@@ -55,6 +55,7 @@ module.exports = config => {
 
   /* eslint-disable no-param-reassign */
   if (process.env.GITHUB_ACTION) {
+    config.reporters = ['dots', 'saucelabs'];
     config.transports = ['polling'];
     config.browsers = [process.env.BROWSER];
     config.browserDisconnectTimeout = 10000;

+ 1 - 0
_develop/webpack.config.js

@@ -65,6 +65,7 @@ const baseConfig = {
     'quill.bubble': './assets/bubble.styl',
     'quill.snow': './assets/snow.styl',
     'unit.js': './test/unit.js',
+    'fuzz.js': './test/fuzz.ts',
   },
   output: {
     filename: '[name]',

File diff suppressed because it is too large
+ 713 - 6
package-lock.json


+ 6 - 7
package.json

@@ -51,6 +51,7 @@
     "karma-chrome-launcher": "^3.2.0",
     "karma-coverage": "^2.2.0",
     "karma-jasmine": "^5.1.0",
+    "karma-jsdom-launcher": "^14.0.0",
     "karma-sauce-launcher": "^4.3.6",
     "lodash": "^4.17.15",
     "mini-css-extract-plugin": "^2.7.6",
@@ -94,18 +95,16 @@
     "start": "USE_LOCAL_FILE=true run-p start:*",
     "start:webpack": "webpack-dev-server --config _develop/webpack.config.js",
     "start:website": "run-s website:build website:serve",
-    "start:karma": "karma start _develop/karma.config.js --no-single-run --no-browsers",
+    "start:karma": "karma start _develop/karma.unit.config.js --no-single-run --no-browsers",
     "start:proxy": "node _develop/proxy.js",
     "website:build": "npm run build -w website",
     "website:serve": "npm run serve -w website -- --port $npm_package_config_ports_gatsby",
     "website:develop": "npm run develop -w website -- --port $npm_package_config_ports_gatsby",
-    "test": "npm run test:unit; npm run test:random",
-    "test:all": "npm run test:unit; npm run test:functional; npm run test:random",
+    "test": "npm run test:unit; npm run test:fuzz; npm run test:e2e",
+    "test:unit": "npm run build; karma start _develop/karma.unit.config.js",
+    "test:fuzz": "npm run build; karma start _develop/karma.fuzz.config.js",
     "test:e2e": "npx playwright test",
-    "test:unit": "npm run build; karma start _develop/karma.config.js",
-    "test:unit:ci": "npm run build; karma start _develop/karma.config.js --reporters dots,saucelabs",
-    "test:random": "ts-node --preferTsExts -O '{\"module\":\"commonjs\"}' ./node_modules/.bin/jasmine test/random.ts",
-    "test:coverage": "webpack --env.coverage --config _develop/webpack.config.js; karma start _develop/karma.config.js --reporters coverage"
+    "test:coverage": "webpack --env.coverage --config _develop/webpack.config.js; karma start _develop/karma.unit.config.js --reporters coverage"
   },
   "overrides": {
     "saucelabs": "^7.2.2",

+ 2 - 0
test/fuzz.ts

@@ -0,0 +1,2 @@
+import './fuzz/editor.test';
+import './fuzz/tableEmbed.test';

Some files were not shown because too many files changed in this diff