From 44f5ff1ca33165beeb89845995e9f49d7c69efe1 Mon Sep 17 00:00:00 2001 From: Perry Mitchell Date: Thu, 21 Mar 2024 21:31:12 +0200 Subject: [PATCH] Add CI tests --- .github/workflows/test.yml | 18 +++++ .travis.yml | 7 -- __webpack.config.js | 160 ------------------------------------- package.json | 1 - 4 files changed, 18 insertions(+), 168 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml delete mode 100644 __webpack.config.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..2612e32e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,18 @@ +name: Tests + +on: push + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20.x] + steps: + - uses: actions/checkout@v2 + - name: Node.js specs ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run test:format diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 42bccbc4..00000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -language: node_js -script: - - echo '{}' > secrets.json - - npm run test:ci -node_js: - - "8" - - "10" diff --git a/__webpack.config.js b/__webpack.config.js deleted file mode 100644 index 9c177b37..00000000 --- a/__webpack.config.js +++ /dev/null @@ -1,160 +0,0 @@ -const path = require("path"); -const fs = require("fs"); -const { DefinePlugin, NormalModuleReplacementPlugin } = require("webpack"); -const CopyWebpackPlugin = require("copy-webpack-plugin"); -const HtmlWebpackPlugin = require("html-webpack-plugin"); -const { devDependencies, version } = require("./package.json"); -const manifest = require("./resources/manifest.json"); - -const CHANGELOG = path.resolve(__dirname, "./CHANGELOG.md"); -const DIST = path.resolve(__dirname, "./dist"); -const ICONS_PATH = path.join(path.dirname(require.resolve("@buttercup/ui")), "icons"); -const INDEX_TEMPLATE = path.resolve(__dirname, "./resources/template.pug"); -const REACT_PACKAGES = Object.keys(devDependencies).filter(name => /^react(-|$)/.test(name)); -const REDUX_PACKAGES = Object.keys(devDependencies).filter(name => /^redux(-|$)/.test(name)); -const SOURCE = path.resolve(__dirname, "./source"); - -const __configDefines = Object.keys(process.env).reduce((output, key) => { - if (/^_.+_$/.test(key)) { - output[key] = JSON.stringify(process.env[key]); - } - return output; -}, {}); - -function buildManifest(assetNames) { - const newManifest = JSON.parse(JSON.stringify(manifest)); - newManifest.version = version; - assetNames.forEach(assetFilename => { - // console.log("ASSET NAME", assetFilename); - if (/^[^\/\\]+\.js$/.test(assetFilename)) { - // if (/\.js$/.test(assetFilename) && /^vendors-/.test(assetFilename)) { - if (/\bbackground\b/.test(assetFilename) && assetFilename !== "background.js") { - newManifest.background.scripts.unshift(assetFilename); - } - if (/\btab\b/.test(assetFilename) && assetFilename !== "tab.js") { - newManifest.content_scripts[0].js.unshift(assetFilename); - } - } - }); - fs.writeFileSync(path.join(DIST, "./manifest.json"), JSON.stringify(newManifest, undefined, 2)); -} - -module.exports = { - devtool: false, - - entry: { - background: path.join(SOURCE, "./background/index.js"), - dialog: path.join(SOURCE, "./dialog/index.js"), - popup: path.join(SOURCE, "./popup/index.js"), - setup: path.join(SOURCE, "./setup/index.js"), - tab: path.join(SOURCE, "./tab/index.js") - }, - - module: { - rules: [ - { - test: /\.js$/, - use: "babel-loader" - }, - { - test: /\.s[ac]ss$/, - use: ["style-loader", "css-loader", "sass-loader"] - }, - { - test: /\.css$/, - use: ["style-loader", "css-loader"] - }, - { - test: /\.pug$/, - use: "pug-loader" - }, - { - test: /\.(jpg|png|svg|eot|svg|ttf|woff|woff2)$/, - loader: "file-loader", - options: { - name: "[path][name].[hash].[ext]" - } - } - ] - }, - - node: { - Buffer: false, - child_process: "empty", - dns: "empty", - net: "empty", - stream: "empty", - tls: "empty" - }, - - optimization: { - splitChunks: { - automaticNameDelimiter: "-", - chunks: "all", - // chunks: chunk => { - // return chunk.name !== "background"; - // }, - maxSize: 0, - minSize: 30000 - } - }, - - output: { - filename: "[name].js", - path: DIST - }, - - plugins: [ - { - apply: compiler => { - compiler.hooks.afterEmit.tap("AfterEmitPlugin", compilation => { - buildManifest(Object.keys(compilation.getStats().compilation.assets)); - }); - } - }, - new CopyWebpackPlugin([ - { - from: CHANGELOG - }, - { - from: path.join(__dirname, "./resources", "buttercup-*.png") - }, - { - from: ICONS_PATH, - to: "icons" - } - ]), - new DefinePlugin(__configDefines), - new DefinePlugin({ - __VERSION__: JSON.stringify(version) - }), - new HtmlWebpackPlugin({ - title: "Buttercup", - template: INDEX_TEMPLATE, - filename: "popup.html", - inject: "body", - chunks: ["popup"] - }), - new HtmlWebpackPlugin({ - title: `Buttercup v${version}`, - template: INDEX_TEMPLATE, - filename: "setup.html", - inject: "body", - chunks: ["setup"] - }), - new HtmlWebpackPlugin({ - title: `Buttercup v${version}`, - template: INDEX_TEMPLATE, - filename: "dialog.html", - inject: "body", - chunks: ["dialog"] - }), - new NormalModuleReplacementPlugin(/\/iconv-loader/, "node-noop"), - new NormalModuleReplacementPlugin(/random-number-generator|safe-buffer/, "node-noop") - ], - - watchOptions: { - ignored: /node_modules/, - poll: 1000 - } -}; diff --git a/package.json b/package.json index 0a95a22a..afa5971c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "release:firefox:source": "zip -r release/firefox/source.zip . --exclude=/.git* --exclude=/node_modules* --exclude=/.history* --exclude=/dist* --exclude=/release* --exclude=*.DS_Store*", "set-version": "node scripts/version.js", "test": "run-s test:format", - "test:ci": "run-s test release", "test:format": "prettier --check '{{source,test}/**/*.{ts,js},webpack.config.js}'" }, "lint-staged": {