Skip to content

Commit

Permalink
chore: infra for units
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed Dec 20, 2020
1 parent 5d423df commit 1f52a1f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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)
})
})
}
9 changes: 9 additions & 0 deletions packages/feature-flags-webpack-plugin/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
2 changes: 1 addition & 1 deletion packages/feature-flags-webpack-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/feature-flags-webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 1f52a1f

Please sign in to comment.