This repository was archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add filters;unit tests; plugin not change
BREAKING CHANGE: wrap a plugin and not change it
- Loading branch information
Showing
7 changed files
with
134 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,19 @@ module.exports = { | |
} | ||
} | ||
] | ||
] | ||
], | ||
env: { | ||
test: { | ||
presets: [ | ||
[ | ||
'@babel/env', | ||
{ | ||
targets: { | ||
node: true | ||
} | ||
} | ||
] | ||
] | ||
} | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,5 +76,8 @@ | |
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.11" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,82 @@ | ||
import plugins, {when, whenAll} from '../src'; | ||
import should from 'should'; | ||
import sinon from 'sinon'; | ||
import plugins, {when, file, format} from '../src'; | ||
|
||
const stubPlugin = { | ||
name: 'StubPlugin', | ||
outputOptions: sinon.stub(), | ||
generateBundle: sinon.stub(), | ||
renderChunk: sinon.stub() | ||
}; | ||
|
||
const notSupportPlugin = { | ||
name: 'not-support', | ||
renderStart: sinon.stub() | ||
}; | ||
|
||
afterEach(function() { | ||
sinon.restore(); | ||
}); | ||
|
||
describe('rollup-plugin-by-output', function() { | ||
it('when should be work', function() { | ||
// todo: test | ||
describe('filter helps', function() { | ||
it('should work with regexp', function() { | ||
const filter = file(/abc/); | ||
filter({file: '123abcd'}).should.be.true(); | ||
filter({file: '123a bcd'}).should.be.false(); | ||
}); | ||
|
||
it('should work with string', function() { | ||
const filter = format('abc'); | ||
filter({format: 'abc'}).should.be.true(); | ||
filter({format: 'abcd'}).should.be.false(); | ||
}); | ||
|
||
it('should work with function', function() { | ||
const filter = file(f => f); | ||
filter({file: 'abc'}).should.be.ok(); | ||
filter({file: ''}).should.not.be.ok(); | ||
}); | ||
}); | ||
|
||
describe('plugin wrapper', function() { | ||
it('[when] should be work', function() { | ||
const wrappedPlugin = when(o => o.file === 'f', stubPlugin); | ||
wrappedPlugin.should.not.equal(stubPlugin); | ||
|
||
should(wrappedPlugin.outputOptions({})).be.null(); | ||
stubPlugin.outputOptions.should.not.be.called(); | ||
wrappedPlugin.outputOptions({file: 'f'}); | ||
stubPlugin.outputOptions.should.be.called(); | ||
|
||
should(wrappedPlugin.generateBundle({})).be.undefined(); | ||
stubPlugin.generateBundle.should.not.be.called(); | ||
wrappedPlugin.generateBundle({file: 'f'}); | ||
stubPlugin.generateBundle.should.be.called(); | ||
|
||
should(wrappedPlugin.renderChunk(null, null, {})).be.null(); | ||
stubPlugin.renderChunk.should.not.be.called(); | ||
wrappedPlugin.renderChunk(null, null, {file: 'f'}); | ||
stubPlugin.renderChunk.should.be.called(); | ||
}); | ||
|
||
it('[when] should throw with not support hook', function() { | ||
should(() => { | ||
when(o => o.file, notSupportPlugin); | ||
}).throw(/not support/); | ||
}); | ||
|
||
it('[plugins] work with multi plugins', function() { | ||
const filter = o => o.file; | ||
const newPlugins = plugins( | ||
[filter, stubPlugin], | ||
[filter, [stubPlugin, stubPlugin]], | ||
notSupportPlugin | ||
); | ||
|
||
newPlugins.length.should.be.equal(4); | ||
newPlugins.should.not.containEql(stubPlugin); | ||
newPlugins[3].should.be.equal(notSupportPlugin); | ||
}); | ||
}); | ||
}); |