diff --git a/packages/feature-flags-webpack-plugin/__tests__/__internal__/compiler.ts b/packages/feature-flags-webpack-plugin/__tests__/__internal__/compiler.ts new file mode 100644 index 00000000..abad9f0d --- /dev/null +++ b/packages/feature-flags-webpack-plugin/__tests__/__internal__/compiler.ts @@ -0,0 +1,38 @@ +import path from 'path' +import webpack from 'webpack' +import { createFsFromVolume, Volume } from 'memfs' + +export function compiler(fixture: any, options: any = {}) { + const $compiler = webpack({ + context: __dirname, + entry: `./${fixture}`, + output: { + path: path.resolve(__dirname), + filename: 'bundle.js', + }, + module: { + rules: [ + { + test: /\.txt$/, + use: { + loader: path.resolve(__dirname, '../src/loader.js'), + options, + }, + }, + ], + }, + plugins: options.plugins, + }) + + $compiler.outputFileSystem = createFsFromVolume(new Volume()) + $compiler.outputFileSystem.join = path.join.bind(path) + + return new Promise((resolve, reject) => { + $compiler.run((err, stats) => { + if (err) reject(err) + if (stats.hasErrors()) reject(new Error(stats.toJson().errors)) + + resolve(stats) + }) + }) +} diff --git a/packages/feature-flags-webpack-plugin/__tests__/index.test.ts b/packages/feature-flags-webpack-plugin/__tests__/index.test.ts new file mode 100644 index 00000000..716b31f6 --- /dev/null +++ b/packages/feature-flags-webpack-plugin/__tests__/index.test.ts @@ -0,0 +1,9 @@ +import FeatureFlagsWebpackPlugin from '../src/index' +import { compiler } from './__internal__/compiler' + +test('yyy', async () => { + const plugin = new FeatureFlagsWebpackPlugin() + await compiler('', { plugins: [plugin] }) + + expect(1).toBe(1) +}) diff --git a/packages/feature-flags-webpack-plugin/package-lock.json b/packages/feature-flags-webpack-plugin/package-lock.json index 82fe014e..fead01ee 100644 --- a/packages/feature-flags-webpack-plugin/package-lock.json +++ b/packages/feature-flags-webpack-plugin/package-lock.json @@ -1,5 +1,5 @@ { - "name": "@bem/feature-flags-webpack-plugin", + "name": "@bem-react/feature-flags-webpack-plugin", "version": "0.0.1-beta.0", "lockfileVersion": 1, "requires": true, diff --git a/packages/feature-flags-webpack-plugin/package.json b/packages/feature-flags-webpack-plugin/package.json index 5565b189..9ef0ca8b 100644 --- a/packages/feature-flags-webpack-plugin/package.json +++ b/packages/feature-flags-webpack-plugin/package.json @@ -18,11 +18,13 @@ "scripts": { "build": "tsc", "cleanup": "rm -rf lib", + "dev": "tsc -w", "prepublishOnly": "npm run cleanup && npm run build", "unit": "../../node_modules/.bin/jest --config ../../.config/jest/jest.config.js" }, "devDependencies": { - "@types/webpack": "4.41.25", - "typescript": "4.1.3" + "memfs": "3.2.0", + "typescript": "4.1.3", + "webpack": "5.11.0" } }