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

tape testing added #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion uglify-webpack-prototype/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"presets": ["env"],
"plugins": ["./plugin.js"]
"plugins": [
"./plugin.js",
"transform-metamagical-comments"
]
}

3 changes: 0 additions & 3 deletions uglify-webpack-prototype/.vscode/settings.json

This file was deleted.

5 changes: 4 additions & 1 deletion uglify-webpack-prototype/dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
return __webpack_require__(__webpack_require__.s = 0);
})([ function(module, exports, __webpack_require__) {
"use strict";
var olleh = "hi";
function square(n) {
return n * n;
}
var hello = "hi";
} ]);
12 changes: 7 additions & 5 deletions uglify-webpack-prototype/lib/AddNumbers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"use strict";

stset = {};
tests = {};

stset.rebmuNddA = function (a, b) {
//! ~dab/changedddddd/
tests.AddNumber = function (a, b) {
return a + b;
};

stset.rebmuNelpitluM = function (a, b) {
//! hi there
/* ~dab/changedddddd/*/
tests.MultipleNumber = function (a, b) {
return a * b;
};

eludom.stropxe = stset;
module.exports = tests;
13 changes: 10 additions & 3 deletions uglify-webpack-prototype/lib/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

/* dab var app=require("../src/AddNumbers.js");
/* ~dab/changedddddd/src/AddNumbers.js");

describe("Addition",function(){
it("The function should add 2 numbers",function() {
Expand All @@ -14,8 +14,15 @@ describe("Multiply",function(){
let value = app.MultipleNumber(5,5);
expect(value).toBe(20);
});
});
});/

*/

var olleh = "hi";
//! ~dab/changedddddd/

//!hi there

function square(n) {
return n * n;
}
var hello = "hi";
8 changes: 0 additions & 8 deletions uglify-webpack-prototype/lib/test.js

This file was deleted.

21 changes: 21 additions & 0 deletions uglify-webpack-prototype/myPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function myPlugin(options) {}

myPlugin.prototype.apply = function(compiler) {
compiler.plugin('emit', function(compilation, callback) {
var source = compilation.assets["../spec/AddNumberSpec.js"].source();
console.log("hello", source);

compilation.assets['../spec/AddNumberSpec.js'] = {
source: function() {
return source.replace(/(\/\* dab)|(\*\/)/g, " ");
},
size: function() {
return "hello";
}
};

callback();
});
};

module.exports = myPlugin;
3 changes: 3 additions & 0 deletions uglify-webpack-prototype/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"babel-plugin-transform-metamagical-comments": "^0.14.0",
"babel-traverse": "^6.25.0",
"babel-types": "^6.25.0",
"babylon": "^6.17.3"
Expand All @@ -22,11 +23,13 @@
"babel-preset-env": "^1.5.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babelify": "^7.3.0",
"css-loader": "^0.28.4",
"html-webpack-plugin": "^2.28.0",
"install": "^0.10.1",
"jasmine": "^2.6.0",
"style-loader": "^0.18.2",
"tape": "^4.6.3",
"uglify-js": "^2.8.29",
"uglifyjs-webpack-plugin": "^0.4.3",
"webpack": "^2.6.1",
Expand Down
16 changes: 13 additions & 3 deletions uglify-webpack-prototype/plugin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
module.exports = function ({types: t}) {
return {
visitor: {
Identifier(path) {
// console.log('this is ', path.node.name);
path.node.name = path.node.name.split('').reverse().join('');
Program(node) {
// path.node.name = path.node.name.split('').reverse().join('');
let array = node.parent.comments;
for (let i = 0; i < array.length; i++) {
var eachObj = array[i];
var value = eachObj.value;
if (value.indexOf("~dab") > -1){
var newVal = value.split("/");
newVal[1] = "changedddddd";
eachObj.value = newVal.join("/");
}
}
}
}
};
}

4 changes: 2 additions & 2 deletions uglify-webpack-prototype/spec/AddNumberSpec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* dab var app=require("../src/AddNumbers.js");
var app=require("../src/AddNumbers.js");

describe("Addition",function(){
it("The function should add 2 numbers",function() {
Expand All @@ -14,4 +14,4 @@ describe("Multiply",function(){
});
});

*/
4 changes: 3 additions & 1 deletion uglify-webpack-prototype/src/AddNumbers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
tests ={};

//! ~dab/hello ,there/
tests.AddNumber = function(a,b){
return a+b;
};

//! hi there
/* ~dab/I dont care/*/
tests.MultipleNumber = function(a,b){
return a * b;
}
Expand Down
4 changes: 4 additions & 0 deletions uglify-webpack-prototype/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ describe("Multiply",function(){



//!hi there

function square(n){
return n*n;
}
let hello = "hi";
15 changes: 15 additions & 0 deletions uglify-webpack-prototype/test-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var test = require('tape');
var tests = require('./src/AddNumbers');

test("multiply: multiply the number by itself", function(t){
let actual = tests.MultipleNumber(2,3)
t.equal(actual, 5, "correct");
t.end();
});

test("multiply: multiply the number by itself", function(t){
let actual = tests.MultipleNumber(2,3)

t.notEqual(actual, 5);
t.end();
});
4 changes: 3 additions & 1 deletion uglify-webpack-prototype/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
const myPlugin = require('./myPlugin.js');


module.exports = {
Expand All @@ -24,7 +25,8 @@ module.exports = {
condition: /dab/,
filename: '../spec/AddNumberSpec.js'
},
})
}),
new myPlugin()
]

};