[react-packager] Fix lint errors

This commit is contained in:
Amjad Masad 2015-02-25 20:29:14 -08:00
parent 3d65001426
commit d740d17d42
32 changed files with 198 additions and 254 deletions

View File

@ -1,86 +0,0 @@
{
"-W093": true,
"asi": false,
"bitwise": true,
"boss": false,
"browser": false,
"camelcase": true,
"couch": false,
"curly": true,
"debug": false,
"devel": true,
"dojo": false,
"eqeqeq": true,
"eqnull": true,
"esnext": true,
"evil": false,
"expr": true,
"forin": false,
"freeze": true,
"funcscope": true,
"gcl": false,
"globals": {
"Promise": true,
"React": true,
"XMLHttpRequest": true,
"document": true,
"location": true,
"window": true
},
"globalstrict": true,
"immed": false,
"indent": 2,
"iterator": false,
"jquery": false,
"lastsemic": false,
"latedef": false,
"laxbreak": true,
"laxcomma": false,
"loopfunc": false,
"maxcomplexity": false,
"maxdepth": false,
"maxerr": 50,
"maxlen": 80,
"maxparams": false,
"maxstatements": false,
"mootools": false,
"moz": false,
"multistr": false,
"newcap": true,
"noarg": true,
"node": true,
"noempty": false,
"nonbsp": true,
"nonew": true,
"nonstandard": false,
"notypeof": false,
"noyield": false,
"phantom": false,
"plusplus": false,
"predef": [
"afterEach",
"beforeEach",
"describe",
"expect",
"it",
"jest",
"pit"
],
"proto": false,
"prototypejs": false,
"quotmark": true,
"rhino": false,
"scripturl": false,
"shadow": false,
"smarttabs": false,
"strict": false,
"sub": false,
"supernew": false,
"trailing": true,
"undef": true,
"unused": true,
"validthis": false,
"worker": false,
"wsh": false,
"yui": false
}

View File

@ -1,3 +1,5 @@
'use strict';
jest.autoMockOff();
describe('Activity', function() {

View File

@ -1,3 +1,5 @@
'use strict';
var COLLECTION_PERIOD = 1000;
var _endedEvents = Object.create(null);

View File

@ -1,3 +1,5 @@
'use strict';
function ModuleDescriptor(fields) {
if (!fields.id) {
throw new Error('Missing required fields id');
@ -28,7 +30,7 @@ ModuleDescriptor.prototype.toJSON = function() {
id: this.id,
path: this.path,
dependencies: this.dependencies
}
};
};
module.exports = ModuleDescriptor;

View File

@ -9,8 +9,6 @@ jest
.dontMock('../docblock')
.setMock('../../../ModuleDescriptor', function(data) {return data;});
var q = require('q');
describe('DependencyGraph', function() {
var DependencyGraph;
var fileWatcher;
@ -46,7 +44,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([
@ -75,7 +76,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([
@ -105,7 +109,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([
@ -135,7 +142,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([
@ -175,7 +185,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/somedir/somefile.js'))
.toEqual([
@ -216,7 +229,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([
@ -245,7 +261,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([
@ -280,7 +299,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([
@ -320,7 +342,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([
@ -360,7 +385,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
expect(dgraph.getOrderedDependencies('/root/index.js'))
.toEqual([
@ -386,7 +414,6 @@ describe('DependencyGraph', function() {
});
describe('file watch updating', function() {
var fileWatcher;
var triggerFileChange;
beforeEach(function() {
@ -428,7 +455,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
filesystem.root['index.js'] =
filesystem.root['index.js'].replace('require("foo")', '');
@ -476,7 +506,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
filesystem.root['index.js'] =
filesystem.root['index.js'].replace('require("foo")', '');
@ -524,7 +557,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
delete filesystem.root.foo;
triggerFileChange('delete', 'foo.js', root);
@ -571,7 +607,10 @@ describe('DependencyGraph', function() {
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
filesystem.root['bar.js'] = [
'/**',
@ -679,7 +718,7 @@ describe('DependencyGraph', function() {
pit('should ignore directory updates', function() {
var root = '/root';
var filesystem = fs.__setMockFilesystem({
fs.__setMockFilesystem({
'root': {
'index.js': [
'/**',
@ -703,7 +742,10 @@ describe('DependencyGraph', function() {
}
}
});
var dgraph = new DependencyGraph({roots: [root], fileWatcher: fileWatcher});
var dgraph = new DependencyGraph({
roots: [root],
fileWatcher: fileWatcher
});
return dgraph.load().then(function() {
triggerFileChange('change', 'aPackage', '/root', {
isDirectory: function(){ return true; }

View File

@ -14,6 +14,7 @@
* limitations under the License.
*/
'use strict';
var docblockRe = /^\s*(\/\*\*(.|\r?\n)*?\*\/)/;
@ -35,7 +36,8 @@ var commentStartRe = /^\/\*\*?/;
var commentEndRe = /\*\/$/;
var wsRe = /[\t ]+/g;
var stringStartRe = /(\r?\n|^) *\*/g;
var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
var multilineRe =
/(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
/**
@ -51,15 +53,15 @@ function parse(docblock) {
// Normalize multi-line directives
var prev = '';
while (prev != docblock) {
while (prev !== docblock) {
prev = docblock;
docblock = docblock.replace(multilineRe, "\n$1 $2\n");
docblock = docblock.replace(multilineRe, '\n$1 $2\n');
}
docblock = docblock.trim();
var result = [];
var match;
while (match = propertyRe.exec(docblock)) {
while ((match = propertyRe.exec(docblock))) {
result.push([match[1], match[2]]);
}

View File

@ -1,25 +0,0 @@
var path = require('path');
var DependecyGraph = require('./');
var example_project = path.resolve(__dirname, '../../../../example_project');
var watcher = new (require('../../../FileWatcher'))({projectRoot: example_project});
var graph = new DependecyGraph({
fileWatcher: watcher,
root: example_project
});
graph.load().then(function() {
var index = path.join(example_project, 'index.js');
console.log(graph.getOrderedDependencies(index));
}).done();
watcher.getWatcher().then(function(watcher) {
watcher.on('all', function() {
setImmediate(function() {
graph.load().then(function() {
var index = path.join(example_project, 'index.js');
console.log(graph.getOrderedDependencies(index));
});
})
});
});

View File

@ -139,7 +139,7 @@ DependecyGraph.prototype.resolveDependency = function(
depModuleId,
fromModule.id
);
return;
return null;
}
var main = packageJson.main || 'index';
@ -223,7 +223,7 @@ DependecyGraph.prototype._search = function() {
.then(function(filePaths) {
filePaths = filePaths.filter(function(filePath) {
if (filePath == null) {
return false
return false;
}
return !self._ignoreFilePath(filePath);
@ -454,7 +454,8 @@ DependecyGraph.prototype._getAbsolutePath = function(filePath) {
return filePath;
}
for (var i = 0, root; root = this._roots[i]; i++) {
for (var i = 0; i < this._roots.length; i++) {
var root = this._roots[i];
var absPath = path.join(root, filePath);
if (this._graph[absPath]) {
return absPath;

View File

@ -1,3 +1,4 @@
'use strict';
jest.dontMock('../')
.dontMock('q')
@ -7,7 +8,6 @@ var q = require('q');
describe('HasteDependencyResolver', function() {
var HasteDependencyResolver;
var DependencyGraph;
beforeEach(function() {
// For the polyfillDeps
@ -15,7 +15,6 @@ describe('HasteDependencyResolver', function() {
return b;
});
HasteDependencyResolver = require('../');
DependencyGraph = require('../DependencyGraph');
});
describe('getDependencies', function() {
@ -223,7 +222,7 @@ describe('HasteDependencyResolver', function() {
});
var depGraph = depResolver._depGraph;
var dependencies = ['x', 'y', 'z']
var dependencies = ['x', 'y', 'z'];
var code = [
'require("x")',
'require("y")',
@ -248,10 +247,10 @@ describe('HasteDependencyResolver', function() {
}, code);
expect(processedCode).toEqual([
"__d('test module',[\"changed\",\"y\"],function(global," +
" require, requireDynamic, requireLazy, module, exports) {" +
" require('changed')",
"require('y')",
'__d(\'test module\',["changed","y"],function(global,' +
' require, requireDynamic, requireLazy, module, exports) {' +
' require(\'changed\')',
'require(\'y\')',
'require("z")});',
].join('\n'));
});

View File

@ -6,14 +6,15 @@ var DependencyGraph = require('./DependencyGraph');
var ModuleDescriptor = require('../ModuleDescriptor');
var declareOpts = require('../../lib/declareOpts');
var DEFINE_MODULE_CODE =
'__d(' +
'\'_moduleName_\',' +
'_deps_,' +
'function(global, require, requireDynamic, requireLazy, module, exports) {'+
' _code_' +
'}' +
');';
var DEFINE_MODULE_CODE = [
'__d(',
'\'_moduleName_\',',
'_deps_,',
'function(global, require, requireDynamic, requireLazy, module, exports) {',
' _code_',
'}',
');',
].join('');
var DEFINE_MODULE_REPLACE_RE = /_moduleName_|_code_|_deps_/g;
@ -116,7 +117,6 @@ HasteDependencyResolver.prototype.wrapModule = function(module, code) {
return code;
}
var depGraph = this._depGraph;
var resolvedDeps = Object.create(null);
var resolvedDepsArr = [];
@ -131,9 +131,9 @@ HasteDependencyResolver.prototype.wrapModule = function(module, code) {
var relativizedCode =
code.replace(REL_REQUIRE_STMT, function(codeMatch, depName) {
var dep = resolvedDeps[depName];
if (dep != null) {
return 'require(\'' + dep + '\')';
var depId = resolvedDeps[depName];
if (depId != null) {
return 'require(\'' + depId + '\')';
} else {
return codeMatch;
}

View File

@ -20,7 +20,9 @@
* @polyfill
*/
/*eslint global-strict:0*/
(function(global) {
'use strict';
var OBJECT_COLUMN_NAME = '(index)';
@ -45,7 +47,7 @@
if (typeof arg.toString === 'function') {
try {
return arg.toString();
} catch (e) {
} catch (E) {
return 'unknown';
}
}
@ -53,7 +55,7 @@
}
}).join(', ');
global.nativeLoggingHook(str);
};
}
var repeat = function(element, n) {
return Array.apply(null, Array(n)).map(function() { return element; });
@ -120,7 +122,7 @@
// logged string, which would shift the header and screw up
// the table
global.nativeLoggingHook('\n' + table.join('\n'));
};
}
global.console = {
error: doNativeLog,
@ -130,7 +132,7 @@
table: consoleTablePolyfill
};
};
}
if (typeof module !== 'undefined') {
module.exports = setupConsole;

View File

@ -39,7 +39,7 @@
return ErrorUtils._inGuard;
},
guard: function(fun, name, context) {
if (typeof fun !== "function") {
if (typeof fun !== 'function') {
console.warn('A function must be passed to ErrorUtils.guard, got ', fun);
return null;
}

View File

@ -22,7 +22,7 @@
// WARNING: This is an optimized version that fails on hasOwnProperty checks
// and non objects. It's not spec-compliant. It's a perf optimization.
/* eslint global-strict:0 */
Object.assign = function(target, sources) {
if (__DEV__) {
if (target == null) {

View File

@ -1 +1,2 @@
/* eslint global-strict:0 */
__DEV__ = false;

View File

@ -1 +1,2 @@
/* eslint global-strict:0 */
__DEV__ = true;

View File

@ -1,3 +1,4 @@
/* eslint global-strict:0,eqeqeq:0,no-bitwise:0,no-undef:0 */
(function(global) {
// avoid redefining require()

View File

@ -1,3 +1,5 @@
'use strict';
var HasteDependencyResolver = require('./haste');
var NodeDependencyResolver = require('./node');

View File

@ -1,17 +1,12 @@
'use strict';
var Promise = require('q').Promise;
var ModuleDescriptor = require('../ModuleDescriptor');
var mdeps = require('module-deps');
var path = require('path');
var fs = require('fs');
// var REQUIRE_RUNTIME = fs.readFileSync(
// path.join(__dirname, 'require.js')
// ).toString();
exports.getRuntimeCode = function() {
return REQUIRE_RUNTIME;
};
exports.getRuntimeCode = function() {};
exports.wrapModule = function(id, source) {
return Promise.resolve(
@ -21,7 +16,7 @@ exports.wrapModule = function(id, source) {
};
exports.getDependencies = function(root, fileEntryPath) {
return new Promise(function(resolve, reject) {
return new Promise(function(resolve) {
fileEntryPath = path.join(process.cwd(), root, fileEntryPath);
var md = mdeps();

View File

@ -1,8 +1,12 @@
'use strict';
jest.dontMock('../')
.dontMock('q')
.setMock('child_process', { exec: function(cmd, cb) { cb(null, '/usr/bin/watchman') } });
jest
.dontMock('../')
.dontMock('q')
.setMock(
'child_process',
{ exec: function(cmd, cb) { cb(null, '/usr/bin/watchman'); } }
);
describe('FileWatcher', function() {
var FileWatcher;

View File

@ -3,7 +3,7 @@
var path = require('path');
var version = require('../../../../package.json').version;
var tmpdir = require('os').tmpDir();
var pathUtils = require('../fb-path-utils');
var isAbsolutePath = require('absolute-path');
var declareOpts = require('../lib/declareOpts');
var fs = require('fs');
var _ = require('underscore');
@ -48,7 +48,7 @@ function Cache(options) {
}
Cache.prototype.get = function(filepath, loaderCb) {
if (!pathUtils.isAbsolutePath(filepath)) {
if (!isAbsolutePath(filepath)) {
throw new Error('Use absolute paths');
}
@ -62,7 +62,7 @@ Cache.prototype.get = function(filepath, loaderCb) {
};
Cache.prototype._set = function(filepath, loaderPromise) {
return this._data[filepath] = loaderPromise.then(function(data) {
this._data[filepath] = loaderPromise.then(function(data) {
return [
data,
q.nfbind(fs.stat)(filepath)
@ -74,10 +74,12 @@ Cache.prototype._set = function(filepath, loaderPromise) {
mtime: stat.mtime.getTime(),
};
}.bind(this));
return this._data[filepath];
};
Cache.prototype.invalidate = function(filepath){
if(this._has(filepath)) {
if (this._has(filepath)) {
delete this._data[filepath];
}
};
@ -94,7 +96,7 @@ Cache.prototype._persistCache = function() {
var data = this._data;
var cacheFilepath = this._cacheFilePath;
return this._persisting = q.all(_.values(data))
this._persisting = q.all(_.values(data))
.then(function(values) {
var json = Object.create(null);
Object.keys(data).forEach(function(key, i) {
@ -106,6 +108,8 @@ Cache.prototype._persistCache = function() {
this._persisting = null;
return true;
}.bind(this));
return this._persisting;
};
function loadCacheSync(cacheFilepath) {

View File

@ -5,7 +5,6 @@ jest
.dontMock('path')
.dontMock('q')
.dontMock('absolute-path')
.dontMock('../../fb-path-utils')
.dontMock('../Cache');
var q = require('q');

View File

@ -7,6 +7,7 @@ var Cache = require('./Cache');
var _ = require('underscore');
var workerFarm = require('worker-farm');
var declareOpts = require('../lib/declareOpts');
var util = require('util');
var readFile = q.nfbind(fs.readFile);
@ -75,9 +76,7 @@ Transformer.prototype.kill = function() {
Transformer.prototype.invalidateFile = function(filePath) {
this._cache.invalidate(filePath);
//TODO: We can read the file and put it into the cache right here
// This would simplify some caching logic as we can be sure that the cache is up to date
}
};
Transformer.prototype.loadFileAndTransform = function(
transformSets,
@ -116,7 +115,7 @@ Transformer.prototype.loadFileAndTransform = function(
};
function TransformError() {}
TransformError.__proto__ = SyntaxError.prototype;
util.inherits(TransformError, SyntaxError);
function formatEsprimaError(err, filename, source) {
if (!(err.lineNumber && err.column)) {

View File

@ -1,7 +1,6 @@
'use strict';
var _ = require('underscore');
var SourceMapGenerator = require('source-map').SourceMapGenerator;
var base64VLQ = require('./base64-vlq');
module.exports = Package;
@ -102,7 +101,7 @@ Package.prototype._getMappings = function() {
mappings += ';';
}
}
if (i != modules.length - 1) {
if (i !== modules.length - 1) {
mappings += ';';
}
}

View File

@ -1,5 +0,0 @@
var SourceMapGenerator = jest.genMockFn();
SourceMapGenerator.prototype.addMapping = jest.genMockFn();
SourceMapGenerator.prototype.setSourceContent = jest.genMockFn();
SourceMapGenerator.prototype.toJSON = jest.genMockFn();
exports.SourceMapGenerator = SourceMapGenerator;

View File

@ -50,13 +50,13 @@ describe('Package', function() {
describe('sourcemap package', function() {
it('should create sourcemap', function() {
var ppackage = new Package('test_url');
ppackage.addModule('transformed foo;\n', 'source foo', 'foo path');
ppackage.addModule('transformed bar;\n', 'source bar', 'bar path');
ppackage.setMainModuleId('foo');
ppackage.finalize({runMainModule: true});
var s = ppackage.getSourceMap();
expect(s).toEqual(genSourceMap(ppackage._modules));
var p = new Package('test_url');
p.addModule('transformed foo;\n', 'source foo', 'foo path');
p.addModule('transformed bar;\n', 'source bar', 'bar path');
p.setMainModuleId('foo');
p.finalize({runMainModule: true});
var s = p.getSourceMap();
expect(s).toEqual(genSourceMap(p._modules));
});
});
});
@ -92,4 +92,4 @@ describe('Package', function() {
);
}
return sourceMapGen.toJSON();
};
}

View File

@ -35,9 +35,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*eslint no-bitwise:0,quotes:0,global-strict:0*/
var charToIntMap = {};
var intToCharMap = {};
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
.split('')
.forEach(function (ch, index) {
@ -55,7 +57,7 @@ base64.encode = function base64_encode(aNumber) {
}
throw new TypeError("Must be between 0 and 63: " + aNumber);
};
/**
* Decode a single base 64 digit to an integer.
*/
@ -65,7 +67,7 @@ base64.decode = function base64_decode(aChar) {
}
throw new TypeError("Not a valid base 64 digit: " + aChar);
};
// A single base 64 digit can contain 6 bits of data. For the base 64 variable
@ -165,4 +167,3 @@ exports.decode = function base64VLQ_decode(aStr, aOutParam) {
aOutParam.value = fromVLQSigned(result);
aOutParam.rest = aStr.slice(i);
};

View File

@ -1,4 +1,6 @@
jest.setMock('worker-farm', function(){ return function(){}; })
'use strict';
jest.setMock('worker-farm', function() { return function() {}; })
.dontMock('q')
.dontMock('os')
.dontMock('errno/custom')
@ -8,9 +10,8 @@ jest.setMock('worker-farm', function(){ return function(){}; })
var q = require('q');
describe('processRequest', function(){
describe('processRequest', function() {
var server;
var Activity;
var Packager;
var FileWatcher;
@ -21,16 +22,16 @@ describe('processRequest', function(){
polyfillModuleNames: null
};
var makeRequest = function(requestHandler, requrl){
var makeRequest = function(requestHandler, requrl) {
var deferred = q.defer();
requestHandler({
url: requrl
},{
end: function(res){
end: function(res) {
deferred.resolve(res);
}
},{
next: function(){}
next: function() {}
}
);
return deferred.promise;
@ -40,8 +41,7 @@ describe('processRequest', function(){
var watcherFunc = jest.genMockFunction();
var requestHandler;
beforeEach(function(){
Activity = require('../../Activity');
beforeEach(function() {
Packager = require('../../Packager');
FileWatcher = require('../../FileWatcher');
@ -50,7 +50,7 @@ describe('processRequest', function(){
getSource: function() {
return 'this is the source';
},
getSourceMap: function(){
getSourceMap: function() {
return 'this is the source map';
},
});
@ -65,26 +65,32 @@ describe('processRequest', function(){
requestHandler = server.processRequest.bind(server);
});
pit('returns JS bundle source on request of *.bundle',function(){
result = makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle');
return result.then(function(response){
expect(response).toEqual("this is the source");
pit('returns JS bundle source on request of *.bundle',function() {
return makeRequest(
requestHandler,
'mybundle.includeRequire.runModule.bundle'
).then(function(response) {
expect(response).toEqual('this is the source');
});
});
pit('returns sourcemap on request of *.map', function(){
result = makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle.map');
return result.then(function(response){
expect(response).toEqual('"this is the source map"');
pit('returns sourcemap on request of *.map', function() {
makeRequest(
requestHandler,
'mybundle.includeRequire.runModule.bundle.map'
).then(function(response) {
expect(response).toEqual('this is the source map');
});
});
pit('watches all files in projectRoot', function(){
result = makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle');
return result.then(function(response){
pit('watches all files in projectRoot', function() {
makeRequest(
requestHandler,
'mybundle.includeRequire.runModule.bundle'
).then(function(response) {
expect(watcherFunc.mock.calls[0][0]).toEqual('all');
expect(watcherFunc.mock.calls[0][1]).not.toBe(null);
})
});
});
@ -101,8 +107,10 @@ describe('processRequest', function(){
});
pit('invalides files in package when file is updated', function() {
result = makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle');
return result.then(function(response){
makeRequest(
requestHandler,
'mybundle.includeRequire.runModule.bundle'
).then(function(response) {
var onFileChange = watcherFunc.mock.calls[0][1];
onFileChange('all','path/file.js', options.projectRoots[0]);
expect(invalidatorFunc.mock.calls[0][0]).toEqual('root/path/file.js');
@ -114,41 +122,41 @@ describe('processRequest', function(){
packageFunc
.mockReturnValueOnce(
q({
getSource: function(){
return "this is the first source"
getSource: function() {
return 'this is the first source';
},
getSourceMap: function(){},
getSourceMap: function() {},
})
)
.mockReturnValue(
q({
getSource: function(){
return "this is the rebuilt source"
getSource: function() {
return 'this is the rebuilt source';
},
getSourceMap: function(){},
getSourceMap: function() {},
})
);
Packager.prototype.package = packageFunc;
var Server = require('../../Server');
var server = new Server(options);
server = new Server(options);
requestHandler = server.processRequest.bind(server);
return makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle')
.then(function(response){
expect(response).toEqual("this is the first source");
.then(function(response) {
expect(response).toEqual('this is the first source');
expect(packageFunc.mock.calls.length).toBe(1);
triggerFileChange('all','path/file.js', options.projectRoots[0]);
jest.runAllTimers();
})
.then(function(){
.then(function() {
expect(packageFunc.mock.calls.length).toBe(2);
return makeRequest(requestHandler,'mybundle.includeRequire.runModule.bundle')
.then(function(response){
expect(response).toEqual("this is the rebuilt source");
.then(function(response) {
expect(response).toEqual('this is the rebuilt source');
});
});
});

View File

@ -1,3 +1,5 @@
'use strict';
var url = require('url');
var path = require('path');
var declareOpts = require('../lib/declareOpts');
@ -154,7 +156,7 @@ Server.prototype.processRequest = function(req, res, next) {
var startReqEventId = Activity.startEvent('request:' + req.url);
var options = getOptionsFromPath(url.parse(req.url).pathname);
var building = this._packages[req.url] || this._buildPackage(options)
var building = this._packages[req.url] || this._buildPackage(options);
this._packages[req.url] = building;
building.then(
function(p) {

View File

@ -1,14 +0,0 @@
var absolutePath = require('absolute-path');
var path = require('path');
var pathIsInside = require('path-is-inside');
function isAbsolutePath(pathStr) {
return absolutePath(pathStr);
}
function isChildPath(parentPath, childPath) {
return pathIsInside(parentPath, childPath);
}
exports.isAbsolutePath = isAbsolutePath;
exports.isChildPath = isChildPath;

View File

@ -1,3 +1,5 @@
'use strict';
module.exports = function(declared) {
return function(opts) {
for (var p in declared) {

View File

@ -1,3 +1,5 @@
'use strict';
jest.autoMockOff();
var declareOpts = require('../declareOpts');

View File

@ -10,6 +10,8 @@
* var myOptions = validate(someOptions);
*/
'use strict';
var Joi = require('joi');
module.exports = function(descriptor) {