react / wstein / node_modules / jest-cli / node_modules / node-haste / lib / loader / JSMockLoader.js
80668 views/**1* Copyright 2013 Facebook, Inc.2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/15var inherits = require('util').inherits;1617var extract = require('../parse/extract');18var ResourceLoader = require('./ResourceLoader');19var JSMock = require('../resource/JSMock');2021/**22* @class Loads and parses __mocks__ / *.js files23*24* @extends {ResourceLoader}25*/26function JSMockLoader(options) {27ResourceLoader.call(this, options);2829this.pathRe = this.options.matchSubDirs ?30/(?:[\\/]|^)__mocks__[\\/](.+)\.js$/ :31/(?:[\\/]|^)__mocks__[\\/]([^\/]+)\.js$/;32}33inherits(JSMockLoader, ResourceLoader);34JSMockLoader.prototype.path = __filename;3536JSMockLoader.prototype.getResourceTypes = function() {37return [JSMock];38};3940JSMockLoader.prototype.getExtensions = function() {41return ['.js'];42};434445/**46* Initialize a resource with the source code and configuration47* Loader can parse, gzip, minify the source code to build the resulting48* Resource value object.49*50* @protected51* @param {String} path resource being built52* @param {ProjectConfiguration} configuration configuration for the path53* @param {String} sourceCode54* @param {Function} callback55*/56JSMockLoader.prototype.loadFromSource =57function(path, configuration, sourceCode, messages, callback) {58var mock = new JSMock(path);59mock.id = path.match(this.pathRe)[1];60mock.requiredModules = extract.requireCalls(sourceCode);61callback(messages, mock);62};6364/**65* Only match __mocks__ / *.js files66* @static67* @param {String} filePath68* @return {Boolean}69*/70JSMockLoader.prototype.matchPath = function(filePath) {71return this.pathRe.test(filePath);72};737475module.exports = JSMockLoader;767778