forked from emberjs/data
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
281 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# test directories | ||
__tests__ | ||
test | ||
tests | ||
powered-test | ||
|
||
# asset directories | ||
docs | ||
doc | ||
website | ||
images | ||
assets | ||
|
||
# examples | ||
example | ||
examples | ||
|
||
# code coverage directories | ||
coverage | ||
.nyc_output | ||
|
||
# build scripts | ||
Makefile | ||
Gulpfile.js | ||
Gruntfile.js | ||
|
||
# configs | ||
.tern-project | ||
.gitattributes | ||
.editorconfig | ||
.*ignore | ||
.eslintrc | ||
.jshintrc | ||
.flowconfig | ||
.documentup.json | ||
.yarn-metadata.json | ||
.*.yml | ||
*.yml | ||
|
||
# misc | ||
*.gz | ||
*.md |
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
const BroccoliTestHelper = require('broccoli-test-helper'); | ||
const co = require('co'); | ||
const Babel = require('broccoli-babel-transpiler'); | ||
const chai = require('ember-cli-blueprint-test-helpers/chai'); | ||
const stripIndent = require('common-tags').stripIndent; | ||
const StripFilteredImports = require('../../lib/transforms/babel-plugin-remove-imports'); | ||
|
||
const { expect } = chai; | ||
const createTempDir = BroccoliTestHelper.createTempDir; | ||
const createBuilder = BroccoliTestHelper.createBuilder; | ||
|
||
function stripNewlines(str) { | ||
return str.replace(/[\r\n]/g, ''); | ||
} | ||
|
||
describe('Unit: babel-plugin-remove-filtered-imports', function() { | ||
let plugins, pluginOptions; | ||
let input, output; | ||
|
||
function transform(code) { | ||
return co.wrap(function* () { | ||
input.write({ 'test.js': code }); | ||
let babel = new Babel(input.path(), { | ||
plugins | ||
}); | ||
|
||
output = createBuilder(babel); | ||
|
||
yield output.build(); | ||
})(); | ||
} | ||
|
||
function getOutput() { | ||
const transpiled = output.read(); | ||
|
||
return stripNewlines(transpiled['test.js']); | ||
} | ||
|
||
beforeEach(co.wrap(function* () { | ||
pluginOptions = {}; | ||
|
||
plugins = [ | ||
[StripFilteredImports, pluginOptions] | ||
]; | ||
|
||
input = yield createTempDir(); | ||
})); | ||
|
||
afterEach(co.wrap(function* () { | ||
if (input) { | ||
yield input.dispose(); | ||
} | ||
if (output) { | ||
yield output.dispose(); | ||
} | ||
|
||
input = output = undefined; | ||
})); | ||
|
||
it('Returns a plugin', function() { | ||
let plugin = StripFilteredImports(); | ||
expect(plugin).to.be.ok; | ||
}); | ||
|
||
it('Does not alter a file if no imports are meant to be filtered', co.wrap(function*() { | ||
let input = stripIndent` | ||
import Foo from 'bar'; | ||
import { baz } from 'none'; | ||
import * as drinks from 'drinks'; | ||
import 'bem'; | ||
`; | ||
|
||
yield transform(input); | ||
|
||
expect(getOutput()).to.equal(stripNewlines(input)); | ||
})); | ||
|
||
it('Properly strips desired imports and specifiers', co.wrap(function*() { | ||
let input = stripIndent` | ||
import Foo from 'bar'; | ||
import { bit } from 'wow'; | ||
import { baz, bell } from 'none'; | ||
import { foo } from 'happy'; | ||
import * as drinks from 'drinks'; | ||
import * as dranks from 'dranks'; | ||
import 'bem'; | ||
import 'bosh'; | ||
import 'bell'; | ||
`; | ||
|
||
pluginOptions.none = ['baz']; | ||
pluginOptions.bar = true; | ||
pluginOptions.drinks = '*'; | ||
pluginOptions.wow = ['bit']; | ||
pluginOptions.bem = ['biz']; | ||
pluginOptions.bosh = '*'; | ||
pluginOptions.dranks = ['bex']; | ||
pluginOptions.bell = true; | ||
|
||
yield transform(input); | ||
let expectedOutput = stripNewlines(stripIndent` | ||
import { bell } from 'none'; | ||
import { foo } from 'happy'; | ||
import * as dranks from 'dranks'; | ||
import 'bem'; | ||
`); | ||
|
||
expect(getOutput()).to.equal(expectedOutput); | ||
})); | ||
}); |
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
Oops, something went wrong.