Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Sep 14, 2017
1 parent 998da44 commit 1db72d7
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/transforms/babel-plugin-remove-imports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function removeImports() {
function PluginRemoveFilteredImports() {
var importDeclarationsToRemove;
var filteredImports;
var filteredImportNames;
Expand Down Expand Up @@ -54,8 +54,8 @@ function removeImports() {
};
}

removeImports.baseDir = function() {
PluginRemoveFilteredImports.baseDir = function() {
return __dirname;
};

module.exports = removeImports;
module.exports = PluginRemoveFilteredImports;
57 changes: 57 additions & 0 deletions node-tests/unit/babel-plugin-remove-imports-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const chai = require('ember-cli-blueprint-test-helpers/chai');
const babel = require('babel-core');
const stripIndent = require('common-tags').stripIndent;
const StripFilteredImports = require('../../lib/transforms/babel-plugin-remove-imports');
const { expect } = chai;

describe('Unit: babel-plugin-remove-filtered-imports', function() {
let plugins, pluginOptions;

function transform(code) {
return babel.transform(code, {
plugins
}).code.trim();
}

beforeEach(function() {
pluginOptions = {};

plugins = [
[StripFilteredImports, pluginOptions]
];
});

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', function() {
let input = stripIndent`
import Foo from 'bar';
import { baz } from 'none';
import * as drinks from 'drinks';
`;

let output = transform(input);

expect(output).to.equal(input);
});

it('Strips ', function() {
let input = stripIndent`
import Foo from 'bar';
import { baz } from 'none';
import * as drinks from 'drinks';
`;

pluginOptions.none = ['baz'];
pluginOptions.bar = '*';
pluginOptions.drinks = '*';

let output = transform(input);
let expectedOutput = '';

expect(output).to.equal(expectedOutput);
});
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"license": "MIT",
"dependencies": {
"amd-name-resolver": "0.0.7",
"babel-core": "^6.26.0",
"babel-plugin-feature-flags": "^0.3.1",
"babel-plugin-filter-imports": "^0.3.1",
"babel-plugin-transform-es2015-block-scoping": "^6.24.1",
Expand All @@ -33,6 +34,7 @@
"broccoli-rollup": "^1.2.0",
"calculate-cache-key-for-tree": "^1.1.0",
"chalk": "^1.1.1",
"common-tags": "^1.4.0",
"ember-cli-babel": "^6.4.1",
"ember-cli-path-utils": "^1.0.0",
"ember-cli-string-utils": "^1.0.0",
Expand Down
135 changes: 125 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ babel-code-frame@^6.22.0:
esutils "^2.0.2"
js-tokens "^3.0.0"

babel-code-frame@^6.26.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
dependencies:
chalk "^1.1.3"
esutils "^2.0.2"
js-tokens "^3.0.2"

babel-core@^5.0.0, babel-core@^5.8.22:
version "5.8.38"
resolved "https://registry.npmjs.org/babel-core/-/babel-core-5.8.38.tgz#1fcaee79d7e61b750b00b8e54f6dfc9d0af86558"
Expand Down Expand Up @@ -384,6 +392,30 @@ babel-core@^6.14.0, babel-core@^6.24.1:
slash "^1.0.0"
source-map "^0.5.0"

babel-core@^6.26.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-core/-/babel-core-6.26.0.tgz#af32f78b31a6fcef119c87b0fd8d9753f03a0bb8"
dependencies:
babel-code-frame "^6.26.0"
babel-generator "^6.26.0"
babel-helpers "^6.24.1"
babel-messages "^6.23.0"
babel-register "^6.26.0"
babel-runtime "^6.26.0"
babel-template "^6.26.0"
babel-traverse "^6.26.0"
babel-types "^6.26.0"
babylon "^6.18.0"
convert-source-map "^1.5.0"
debug "^2.6.8"
json5 "^0.5.1"
lodash "^4.17.4"
minimatch "^3.0.4"
path-is-absolute "^1.0.1"
private "^0.1.7"
slash "^1.0.0"
source-map "^0.5.6"

babel-generator@^6.25.0:
version "6.25.0"
resolved "https://registry.npmjs.org/babel-generator/-/babel-generator-6.25.0.tgz#33a1af70d5f2890aeb465a4a7793c1df6a9ea9fc"
Expand All @@ -397,6 +429,19 @@ babel-generator@^6.25.0:
source-map "^0.5.0"
trim-right "^1.0.1"

babel-generator@^6.26.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.0.tgz#ac1ae20070b79f6e3ca1d3269613053774f20dc5"
dependencies:
babel-messages "^6.23.0"
babel-runtime "^6.26.0"
babel-types "^6.26.0"
detect-indent "^4.0.0"
jsesc "^1.3.0"
lodash "^4.17.4"
source-map "^0.5.6"
trim-right "^1.0.1"

babel-helper-builder-binary-assignment-operator-visitor@^6.24.1:
version "6.24.1"
resolved "https://registry.npmjs.org/babel-helper-builder-binary-assignment-operator-visitor/-/babel-helper-builder-binary-assignment-operator-visitor-6.24.1.tgz#cce4517ada356f4220bcae8a02c2b346f9a56664"
Expand Down Expand Up @@ -862,6 +907,18 @@ babel-register@^6.24.1:
mkdirp "^0.5.1"
source-map-support "^0.4.2"

babel-register@^6.26.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-register/-/babel-register-6.26.0.tgz#6ed021173e2fcb486d7acb45c6009a856f647071"
dependencies:
babel-core "^6.26.0"
babel-runtime "^6.26.0"
core-js "^2.5.0"
home-or-tmp "^2.0.0"
lodash "^4.17.4"
mkdirp "^0.5.1"
source-map-support "^0.4.15"

babel-runtime@^5.0.0:
version "5.8.38"
resolved "https://registry.npmjs.org/babel-runtime/-/babel-runtime-5.8.38.tgz#1c0b02eb63312f5f087ff20450827b425c9d4c19"
Expand All @@ -875,6 +932,13 @@ babel-runtime@^6.18.0, babel-runtime@^6.22.0:
core-js "^2.4.0"
regenerator-runtime "^0.10.0"

babel-runtime@^6.26.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
dependencies:
core-js "^2.4.0"
regenerator-runtime "^0.11.0"

babel-template@^6.24.1, babel-template@^6.25.0:
version "6.25.0"
resolved "https://registry.npmjs.org/babel-template/-/babel-template-6.25.0.tgz#665241166b7c2aa4c619d71e192969552b10c071"
Expand All @@ -885,6 +949,16 @@ babel-template@^6.24.1, babel-template@^6.25.0:
babylon "^6.17.2"
lodash "^4.2.0"

babel-template@^6.26.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02"
dependencies:
babel-runtime "^6.26.0"
babel-traverse "^6.26.0"
babel-types "^6.26.0"
babylon "^6.18.0"
lodash "^4.17.4"

babel-traverse@^6.24.1, babel-traverse@^6.25.0:
version "6.25.0"
resolved "https://registry.npmjs.org/babel-traverse/-/babel-traverse-6.25.0.tgz#2257497e2fcd19b89edc13c4c91381f9512496f1"
Expand All @@ -899,6 +973,20 @@ babel-traverse@^6.24.1, babel-traverse@^6.25.0:
invariant "^2.2.0"
lodash "^4.2.0"

babel-traverse@^6.26.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee"
dependencies:
babel-code-frame "^6.26.0"
babel-messages "^6.23.0"
babel-runtime "^6.26.0"
babel-types "^6.26.0"
babylon "^6.18.0"
debug "^2.6.8"
globals "^9.18.0"
invariant "^2.2.2"
lodash "^4.17.4"

babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.25.0:
version "6.25.0"
resolved "https://registry.npmjs.org/babel-types/-/babel-types-6.25.0.tgz#70afb248d5660e5d18f811d91c8303b54134a18e"
Expand All @@ -908,6 +996,15 @@ babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.25.0:
lodash "^4.2.0"
to-fast-properties "^1.0.1"

babel-types@^6.26.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497"
dependencies:
babel-runtime "^6.26.0"
esutils "^2.0.2"
lodash "^4.17.4"
to-fast-properties "^1.0.3"

babel6-plugin-strip-class-callcheck@^6.0.0:
version "6.0.0"
resolved "https://registry.npmjs.org/babel6-plugin-strip-class-callcheck/-/babel6-plugin-strip-class-callcheck-6.0.0.tgz#de841c1abebbd39f78de0affb2c9a52ee228fddf"
Expand All @@ -924,6 +1021,10 @@ babylon@^6.17.2:
version "6.17.4"
resolved "https://registry.npmjs.org/babylon/-/babylon-6.17.4.tgz#3e8b7402b88d22c3423e137a1577883b15ff869a"

babylon@^6.18.0:
version "6.18.0"
resolved "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3"

backbone@^1.1.2:
version "1.3.3"
resolved "https://registry.npmjs.org/backbone/-/backbone-1.3.3.tgz#4cc80ea7cb1631ac474889ce40f2f8bc683b2999"
Expand Down Expand Up @@ -1738,6 +1839,12 @@ commander@~2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/commander/-/commander-2.1.0.tgz#d121bbae860d9992a3d517ba96f56588e47c6781"

common-tags@^1.4.0:
version "1.4.0"
resolved "https://registry.npmjs.org/common-tags/-/common-tags-1.4.0.tgz#1187be4f3d4cf0c0427d43f74eef1f73501614c0"
dependencies:
babel-runtime "^6.18.0"

commoner@~0.10.3:
version "0.10.8"
resolved "https://registry.npmjs.org/commoner/-/commoner-0.10.8.tgz#34fc3672cd24393e8bb47e70caa0293811f4f2c5"
Expand Down Expand Up @@ -1853,7 +1960,7 @@ continuable-cache@^0.3.1:
version "0.3.1"
resolved "https://registry.npmjs.org/continuable-cache/-/continuable-cache-0.3.1.tgz#bd727a7faed77e71ff3985ac93351a912733ad0f"

convert-source-map@^1.1.0:
convert-source-map@^1.1.0, convert-source-map@^1.5.0:
version "1.5.0"
resolved "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.5.0.tgz#9acd70851c6d5dfdd93d9282e5edf94a03ff46b5"

Expand All @@ -1877,6 +1984,10 @@ core-js@^2.4.0:
version "2.4.1"
resolved "https://registry.npmjs.org/core-js/-/core-js-2.4.1.tgz#4de911e667b0eae9124e34254b53aea6fc618d3e"

core-js@^2.5.0:
version "2.5.0"
resolved "https://registry.npmjs.org/core-js/-/core-js-2.5.0.tgz#569c050918be6486b3837552028ae0466b717086"

core-object@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/core-object/-/core-object-1.1.0.tgz#86d63918733cf9da1a5aae729e62c0a88e66ad0a"
Expand Down Expand Up @@ -1931,7 +2042,7 @@ dag-map@^2.0.2:
version "2.0.2"
resolved "https://registry.npmjs.org/dag-map/-/dag-map-2.0.2.tgz#9714b472de82a1843de2fba9b6876938cab44c68"

debug@2, [email protected], debug@^2.1.0, debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.4.0, debug@~2.6.7:
debug@2, [email protected], debug@^2.1.0, debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.4.0, debug@^2.6.8, debug@~2.6.7:
version "2.6.8"
resolved "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
dependencies:
Expand Down Expand Up @@ -3356,7 +3467,7 @@ globals@^6.4.0:
version "6.4.1"
resolved "https://registry.npmjs.org/globals/-/globals-6.4.1.tgz#8498032b3b6d1cc81eebc5f79690d8fe29fabf4f"

globals@^9.0.0, globals@^9.2.0:
globals@^9.0.0, globals@^9.18.0, globals@^9.2.0:
version "9.18.0"
resolved "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a"

Expand Down Expand Up @@ -3855,7 +3966,7 @@ [email protected]:
version "1.0.1"
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-1.0.1.tgz#cc435a5c8b94ad15acb7983140fc80182c89aeae"

js-tokens@^3.0.0:
js-tokens@^3.0.0, js-tokens@^3.0.2:
version "3.0.2"
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"

Expand Down Expand Up @@ -3903,7 +4014,7 @@ json5@^0.4.0:
version "0.4.0"
resolved "https://registry.npmjs.org/json5/-/json5-0.4.0.tgz#054352e4c4c80c86c0923877d449de176a732c8d"

json5@^0.5.0:
json5@^0.5.0, json5@^0.5.1:
version "0.5.1"
resolved "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"

Expand Down Expand Up @@ -4202,7 +4313,7 @@ lodash@^3.10.0, lodash@^3.10.1, lodash@^3.9.3:
version "3.10.1"
resolved "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"

lodash@^4.0.0, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.16.1, lodash@^4.2.0, lodash@^4.3.0, lodash@^4.6.1:
lodash@^4.0.0, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.16.1, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0, lodash@^4.6.1:
version "4.17.4"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

Expand Down Expand Up @@ -4748,7 +4859,7 @@ path-exists@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"

path-is-absolute@^1.0.0:
path-is-absolute@^1.0.0, path-is-absolute@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"

Expand Down Expand Up @@ -4829,7 +4940,7 @@ printf@^0.2.3:
version "0.2.5"
resolved "https://registry.npmjs.org/printf/-/printf-0.2.5.tgz#c438ca2ca33e3927671db4ab69c0e52f936a4f0f"

private@^0.1.6, private@~0.1.5:
private@^0.1.6, private@^0.1.7, private@~0.1.5:
version "0.1.7"
resolved "https://registry.npmjs.org/private/-/private-0.1.7.tgz#68ce5e8a1ef0a23bb570cc28537b5332aba63ef1"

Expand Down Expand Up @@ -5015,6 +5126,10 @@ regenerator-runtime@^0.10.0:
version "0.10.5"
resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658"

regenerator-runtime@^0.11.0:
version "0.11.0"
resolved "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1"

[email protected]:
version "0.9.11"
resolved "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.9.11.tgz#3a7d067520cb7b7176769eb5ff868691befe1283"
Expand Down Expand Up @@ -5425,7 +5540,7 @@ source-map-support@^0.2.10:
dependencies:
source-map "0.1.32"

source-map-support@^0.4.0, source-map-support@^0.4.2:
source-map-support@^0.4.0, source-map-support@^0.4.15, source-map-support@^0.4.2:
version "0.4.15"
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.15.tgz#03202df65c06d2bd8c7ec2362a193056fef8d3b1"
dependencies:
Expand Down Expand Up @@ -5716,7 +5831,7 @@ [email protected]:
version "0.1.4"
resolved "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz#17e6c11f73dd4f3d74cda7a4ff3238e9ad9bf890"

to-fast-properties@^1.0.0, to-fast-properties@^1.0.1:
to-fast-properties@^1.0.0, to-fast-properties@^1.0.1, to-fast-properties@^1.0.3:
version "1.0.3"
resolved "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"

Expand Down

0 comments on commit 1db72d7

Please sign in to comment.