Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add Debug test #7

Merged
merged 1 commit into from Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 0 additions & 16 deletions .babelrc.json

This file was deleted.

14 changes: 8 additions & 6 deletions README.md
@@ -1,6 +1,8 @@
# webpack-strip-debug-loader
# [`webpack-strip-debug-loader`](https://www.npmjs.com/package/webpack-strip-debug-loader)

Removes [`debug`](https://www.npmjs.com/package/debug) usage from your source code during Webpack builds.
![CI](https://github.com/morganney/webpack-strip-debug-loader/actions/workflows/ci.yml/badge.svg)

Removes [`debug`](https://www.npmjs.com/package/debug) usage from your source code during webpack builds.

## Usage

Expand All @@ -22,13 +24,13 @@ Just make simple debug statements.
import { Debug } from 'webpack-strip-debug-loader'

// Or use require if you prefer that
const { Debug } = require("webpack-strip-debug-loader")
const { Debug } = require('webpack-strip-debug-loader')

const debug = Debug("feature")
const debug = Debug('feature')
const debugFoo = Debug('foo')

if (somethingOfInterestHappens) {
debug("something happened")
debug('something happened')
}

if (foo) {
Expand All @@ -43,7 +45,7 @@ if (foo) {

### Stripping

To remove the logging and bundling of debug usage register this loader with Webpack.
To remove the logging and bundling of debug usage register this loader with webpack.

```js
module: {
Expand Down
21 changes: 7 additions & 14 deletions __tests__/debug.js
@@ -1,19 +1,12 @@
import { jest } from '@jest/globals'

import { Debug } from '../src/debug.js'

jest.mock('debug')

let debug = null

/**
* Testing that it wraps `debug` has to wait for better
* support for mocks when using ESM
* @see https://github.com/facebook/jest/pull/10976
*/
describe('Debug', () => {
beforeAll(async () => {
;({ default: debug } = await import('debug'))
})

it('wraps debug', () => {
Debug('namespace')

expect(debug).toHaveBeenCalled()
it('returns a function', () => {
expect(Debug('test')).toEqual(expect.any(Function))
})
})
20 changes: 20 additions & 0 deletions babel.config.cjs
@@ -0,0 +1,20 @@
module.exports = function (api) {
const env = process.env.NODE_ENV || 'development'
const presets = [
[
'@babel/preset-env',
{
targets: {
browsers: ['defaults', 'current node']
},
modules: 'commonjs'
}
]
]

api.cache(() => env === 'development')

return {
presets
}
}
5 changes: 0 additions & 5 deletions jest.config.js
Expand Up @@ -10,11 +10,6 @@ export default {
* @see https://github.com/webpack/loader-runner/issues/61
*/
'!**/__tests__/loader.js',
/**
* Has to wait for better support for mocks when using ESM
* @see https://github.com/facebook/jest/pull/10976
*/
'!**/__tests__/debug.js',
'!**/__tests__/__fixtures__/*.js'
],
transform: {}
Expand Down