mirror of https://github.com/status-im/metro.git
Remove `pit` and `mockImpl`
Reviewed By: dmitriiabramov Differential Revision: D4321635 fbshipit-source-id: 460889a1f956f3733e7e49883dd97c9a8a561b86
This commit is contained in:
parent
5da19878c4
commit
c383638e5e
|
@ -26,7 +26,7 @@ describe('Bundle', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('source bundle', () => {
|
describe('source bundle', () => {
|
||||||
pit('should create a bundle and get the source', () => {
|
it('should create a bundle and get the source', () => {
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
return addModule({
|
return addModule({
|
||||||
bundle,
|
bundle,
|
||||||
|
@ -51,7 +51,7 @@ describe('Bundle', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should be ok to leave out the source map url', () => {
|
it('should be ok to leave out the source map url', () => {
|
||||||
const otherBundle = new Bundle();
|
const otherBundle = new Bundle();
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
return addModule({
|
return addModule({
|
||||||
|
@ -76,7 +76,7 @@ describe('Bundle', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should create a bundle and add run module code', () => {
|
it('should create a bundle and add run module code', () => {
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
return addModule({
|
return addModule({
|
||||||
bundle,
|
bundle,
|
||||||
|
@ -107,7 +107,7 @@ describe('Bundle', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should insert modules in a deterministic order, independent from timing of the wrapping process', () => {
|
it('should insert modules in a deterministic order, independent from timing of the wrapping process', () => {
|
||||||
const moduleTransports = [
|
const moduleTransports = [
|
||||||
createModuleTransport({name: 'module1'}),
|
createModuleTransport({name: 'module1'}),
|
||||||
createModuleTransport({name: 'module2'}),
|
createModuleTransport({name: 'module2'}),
|
||||||
|
@ -137,7 +137,7 @@ describe('Bundle', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sourcemap bundle', () => {
|
describe('sourcemap bundle', () => {
|
||||||
pit('should create sourcemap', () => {
|
it('should create sourcemap', () => {
|
||||||
const otherBundle = new Bundle({sourceMapUrl: 'test_url'});
|
const otherBundle = new Bundle({sourceMapUrl: 'test_url'});
|
||||||
|
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
|
@ -181,7 +181,7 @@ describe('Bundle', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should combine sourcemaps', () => {
|
it('should combine sourcemaps', () => {
|
||||||
const otherBundle = new Bundle({sourceMapUrl: 'test_url'});
|
const otherBundle = new Bundle({sourceMapUrl: 'test_url'});
|
||||||
|
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
|
@ -283,7 +283,7 @@ describe('Bundle', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getJSModulePaths()', () => {
|
describe('getJSModulePaths()', () => {
|
||||||
pit('should return module paths', () => {
|
it('should return module paths', () => {
|
||||||
var otherBundle = new Bundle({sourceMapUrl: 'test_url'});
|
var otherBundle = new Bundle({sourceMapUrl: 'test_url'});
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
return addModule({
|
return addModule({
|
||||||
|
|
|
@ -69,20 +69,20 @@ describe('Bundler', function() {
|
||||||
getModuleSystemDependencies = jest.fn();
|
getModuleSystemDependencies = jest.fn();
|
||||||
projectRoots = ['/root'];
|
projectRoots = ['/root'];
|
||||||
|
|
||||||
Resolver.mockImpl(function() {
|
Resolver.mockImplementation(function() {
|
||||||
return {
|
return {
|
||||||
getDependencies: getDependencies,
|
getDependencies: getDependencies,
|
||||||
getModuleSystemDependencies: getModuleSystemDependencies,
|
getModuleSystemDependencies: getModuleSystemDependencies,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.statSync.mockImpl(function() {
|
fs.statSync.mockImplementation(function() {
|
||||||
return {
|
return {
|
||||||
isDirectory: () => true
|
isDirectory: () => true
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.readFile.mockImpl(function(file, callback) {
|
fs.readFile.mockImplementation(function(file, callback) {
|
||||||
callback(null, '{"json":true}');
|
callback(null, '{"json":true}');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ describe('Bundler', function() {
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
getDependencies.mockImpl((main, options, transformOptions) =>
|
getDependencies.mockImplementation((main, options, transformOptions) =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
mainModuleId: 'foo',
|
mainModuleId: 'foo',
|
||||||
dependencies: modules,
|
dependencies: modules,
|
||||||
|
@ -123,17 +123,17 @@ describe('Bundler', function() {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
getModuleSystemDependencies.mockImpl(function() {
|
getModuleSystemDependencies.mockImplementation(function() {
|
||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
|
|
||||||
sizeOf.mockImpl(function(path, cb) {
|
sizeOf.mockImplementation(function(path, cb) {
|
||||||
cb(null, { width: 50, height: 100 });
|
cb(null, { width: 50, height: 100 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('create a bundle', function() {
|
it('create a bundle', function() {
|
||||||
assetServer.getAssetData.mockImpl(() => {
|
assetServer.getAssetData.mockImplementation(() => {
|
||||||
return {
|
return {
|
||||||
scales: [1,2,3],
|
scales: [1,2,3],
|
||||||
files: [
|
files: [
|
||||||
|
@ -217,7 +217,7 @@ describe('Bundler', function() {
|
||||||
name: 'img',
|
name: 'img',
|
||||||
type: 'png',
|
type: 'png',
|
||||||
};
|
};
|
||||||
assetServer.getAssetData.mockImpl(() => mockAsset);
|
assetServer.getAssetData.mockImplementation(() => mockAsset);
|
||||||
|
|
||||||
return bundler.bundle({
|
return bundler.bundle({
|
||||||
entryFile: '/root/foo.js',
|
entryFile: '/root/foo.js',
|
||||||
|
@ -247,7 +247,7 @@ describe('Bundler', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('gets the list of dependencies from the resolver', function() {
|
it('gets the list of dependencies from the resolver', function() {
|
||||||
const entryFile = '/root/foo.js';
|
const entryFile = '/root/foo.js';
|
||||||
return bundler.getDependencies({entryFile, recursive: true}).then(() =>
|
return bundler.getDependencies({entryFile, recursive: true}).then(() =>
|
||||||
// jest calledWith does not support jasmine.any
|
// jest calledWith does not support jasmine.any
|
||||||
|
@ -279,7 +279,7 @@ describe('Bundler', function() {
|
||||||
|
|
||||||
describe('getOrderedDependencyPaths', () => {
|
describe('getOrderedDependencyPaths', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
assetServer.getAssetData.mockImpl(function(relPath) {
|
assetServer.getAssetData.mockImplementation(function(relPath) {
|
||||||
if (relPath === 'img/new_image.png') {
|
if (relPath === 'img/new_image.png') {
|
||||||
return {
|
return {
|
||||||
scales: [1,2,3],
|
scales: [1,2,3],
|
||||||
|
@ -310,7 +310,7 @@ describe('Bundler', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should get the concrete list of all dependency files', () => {
|
it('should get the concrete list of all dependency files', () => {
|
||||||
modules.push(
|
modules.push(
|
||||||
createModule({
|
createModule({
|
||||||
id: 'new_image2.png',
|
id: 'new_image2.png',
|
||||||
|
|
|
@ -36,7 +36,7 @@ describe('Transformer', function() {
|
||||||
fs.writeFileSync.mockClear();
|
fs.writeFileSync.mockClear();
|
||||||
options = {transformModulePath};
|
options = {transformModulePath};
|
||||||
workerFarm.mockClear();
|
workerFarm.mockClear();
|
||||||
workerFarm.mockImpl((opts, path, methods) => {
|
workerFarm.mockImplementation((opts, path, methods) => {
|
||||||
const api = workers = {};
|
const api = workers = {};
|
||||||
methods.forEach(method => {api[method] = jest.fn();});
|
methods.forEach(method => {api[method] = jest.fn();});
|
||||||
return api;
|
return api;
|
||||||
|
@ -57,12 +57,12 @@ describe('Transformer', function() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should add file info to parse errors', function() {
|
it('should add file info to parse errors', function() {
|
||||||
const transformer = new Transformer(options);
|
const transformer = new Transformer(options);
|
||||||
var message = 'message';
|
var message = 'message';
|
||||||
var snippet = 'snippet';
|
var snippet = 'snippet';
|
||||||
|
|
||||||
workers.transformAndExtractDependencies.mockImpl(
|
workers.transformAndExtractDependencies.mockImplementation(
|
||||||
function(transformPath, filename, code, opts, callback) {
|
function(transformPath, filename, code, opts, callback) {
|
||||||
var babelError = new SyntaxError(message);
|
var babelError = new SyntaxError(message);
|
||||||
babelError.type = 'SyntaxError';
|
babelError.type = 'SyntaxError';
|
||||||
|
|
|
@ -70,8 +70,8 @@ describe('Resolver', function() {
|
||||||
function createModule(id, dependencies) {
|
function createModule(id, dependencies) {
|
||||||
var module = new Module({});
|
var module = new Module({});
|
||||||
module.path = id;
|
module.path = id;
|
||||||
module.getName.mockImpl(() => Promise.resolve(id));
|
module.getName.mockImplementation(() => Promise.resolve(id));
|
||||||
module.getDependencies.mockImpl(() => Promise.resolve(dependencies));
|
module.getDependencies.mockImplementation(() => Promise.resolve(dependencies));
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ describe('Resolver', function() {
|
||||||
expect(platforms).toEqual(['ios', 'windows', 'vr']);
|
expect(platforms).toEqual(['ios', 'windows', 'vr']);
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should get dependencies with polyfills', function() {
|
it('should get dependencies with polyfills', function() {
|
||||||
var module = createModule('index');
|
var module = createModule('index');
|
||||||
var deps = [module];
|
var deps = [module];
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ describe('Resolver', function() {
|
||||||
projectRoot: '/root',
|
projectRoot: '/root',
|
||||||
});
|
});
|
||||||
|
|
||||||
DependencyGraph.prototype.getDependencies.mockImpl(function() {
|
DependencyGraph.prototype.getDependencies.mockImplementation(function() {
|
||||||
return Promise.resolve(new ResolutionResponseMock({
|
return Promise.resolve(new ResolutionResponseMock({
|
||||||
dependencies: deps,
|
dependencies: deps,
|
||||||
mainModuleId: 'index',
|
mainModuleId: 'index',
|
||||||
|
@ -237,7 +237,7 @@ describe('Resolver', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should get dependencies with polyfills', function() {
|
it('should get dependencies with polyfills', function() {
|
||||||
var module = createModule('index');
|
var module = createModule('index');
|
||||||
var deps = [module];
|
var deps = [module];
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ describe('Resolver', function() {
|
||||||
projectRoot: '/root',
|
projectRoot: '/root',
|
||||||
});
|
});
|
||||||
|
|
||||||
DependencyGraph.prototype.getDependencies.mockImpl(function() {
|
DependencyGraph.prototype.getDependencies.mockImplementation(function() {
|
||||||
return Promise.resolve(new ResolutionResponseMock({
|
return Promise.resolve(new ResolutionResponseMock({
|
||||||
dependencies: deps,
|
dependencies: deps,
|
||||||
mainModuleId: 'index',
|
mainModuleId: 'index',
|
||||||
|
@ -271,7 +271,7 @@ describe('Resolver', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should pass in more polyfills', function() {
|
it('should pass in more polyfills', function() {
|
||||||
var module = createModule('index');
|
var module = createModule('index');
|
||||||
var deps = [module];
|
var deps = [module];
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ describe('Resolver', function() {
|
||||||
polyfillModuleNames: ['some module'],
|
polyfillModuleNames: ['some module'],
|
||||||
});
|
});
|
||||||
|
|
||||||
DependencyGraph.prototype.getDependencies.mockImpl(function() {
|
DependencyGraph.prototype.getDependencies.mockImplementation(function() {
|
||||||
return Promise.resolve(new ResolutionResponseMock({
|
return Promise.resolve(new ResolutionResponseMock({
|
||||||
dependencies: deps,
|
dependencies: deps,
|
||||||
mainModuleId: 'index',
|
mainModuleId: 'index',
|
||||||
|
@ -325,7 +325,7 @@ describe('Resolver', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should resolve modules', function() {
|
it('should resolve modules', function() {
|
||||||
/*eslint-disable */
|
/*eslint-disable */
|
||||||
var code = [
|
var code = [
|
||||||
// require
|
// require
|
||||||
|
@ -387,7 +387,7 @@ describe('Resolver', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should add module transport names as fourth argument to `__d`', () => {
|
it('should add module transport names as fourth argument to `__d`', () => {
|
||||||
const module = createModule('test module');
|
const module = createModule('test module');
|
||||||
const code = 'arbitrary(code)'
|
const code = 'arbitrary(code)'
|
||||||
const resolutionResponse = new ResolutionResponseMock({
|
const resolutionResponse = new ResolutionResponseMock({
|
||||||
|
@ -409,7 +409,7 @@ describe('Resolver', function() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should pass through passed-in source maps', () => {
|
it('should pass through passed-in source maps', () => {
|
||||||
const module = createModule('test module');
|
const module = createModule('test module');
|
||||||
const resolutionResponse = new ResolutionResponseMock({
|
const resolutionResponse = new ResolutionResponseMock({
|
||||||
dependencies: [module],
|
dependencies: [module],
|
||||||
|
@ -425,7 +425,7 @@ describe('Resolver', function() {
|
||||||
}).then(({map}) => expect(map).toBe(inputMap));
|
}).then(({map}) => expect(map).toBe(inputMap));
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should resolve polyfills', function () {
|
it('should resolve polyfills', function () {
|
||||||
const depResolver = new Resolver({
|
const depResolver = new Resolver({
|
||||||
projectRoot: '/root',
|
projectRoot: '/root',
|
||||||
});
|
});
|
||||||
|
@ -459,7 +459,7 @@ describe('Resolver', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should prefix JSON files with `module.exports=`', () => {
|
it('should prefix JSON files with `module.exports=`', () => {
|
||||||
return depResolver
|
return depResolver
|
||||||
.wrapModule({resolutionResponse, module, name: id, code, dev: false})
|
.wrapModule({resolutionResponse, module, name: id, code, dev: false})
|
||||||
.then(({code: processedCode}) =>
|
.then(({code: processedCode}) =>
|
||||||
|
@ -491,7 +491,7 @@ describe('Resolver', function() {
|
||||||
sourceMap = {version: 3, sources: ['input'], mappings: 'whatever'};
|
sourceMap = {version: 3, sources: ['input'], mappings: 'whatever'};
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should invoke the minifier with the wrapped code', () => {
|
it('should invoke the minifier with the wrapped code', () => {
|
||||||
const wrappedCode =
|
const wrappedCode =
|
||||||
`__d(/* ${id} */function(global, require, module, exports) {${
|
`__d(/* ${id} */function(global, require, module, exports) {${
|
||||||
code}\n}, ${resolutionResponse.getModuleId(module)});`
|
code}\n}, ${resolutionResponse.getModuleId(module)});`
|
||||||
|
@ -509,7 +509,7 @@ describe('Resolver', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should use minified code', () => {
|
it('should use minified code', () => {
|
||||||
const minifiedCode = 'minified(code)';
|
const minifiedCode = 'minified(code)';
|
||||||
const minifiedMap = {version: 3, file: ['minified']};
|
const minifiedMap = {version: 3, file: ['minified']};
|
||||||
minifyCode.mockReturnValue(Promise.resolve({code: minifiedCode, map: minifiedMap}));
|
minifyCode.mockReturnValue(Promise.resolve({code: minifiedCode, map: minifiedMap}));
|
||||||
|
|
|
@ -351,7 +351,7 @@ describe('processRequest', () => {
|
||||||
const req = {url: '/assets/imgs/a.png'};
|
const req = {url: '/assets/imgs/a.png'};
|
||||||
const res = {end: jest.fn(), setHeader: jest.fn()};
|
const res = {end: jest.fn(), setHeader: jest.fn()};
|
||||||
|
|
||||||
AssetServer.prototype.get.mockImpl(() => Promise.resolve('i am image'));
|
AssetServer.prototype.get.mockImplementation(() => Promise.resolve('i am image'));
|
||||||
|
|
||||||
server.processRequest(req, res);
|
server.processRequest(req, res);
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
|
@ -362,7 +362,7 @@ describe('processRequest', () => {
|
||||||
const req = {url: '/assets/imgs/a.png?platform=ios'};
|
const req = {url: '/assets/imgs/a.png?platform=ios'};
|
||||||
const res = {end: jest.fn(), setHeader: jest.fn()};
|
const res = {end: jest.fn(), setHeader: jest.fn()};
|
||||||
|
|
||||||
AssetServer.prototype.get.mockImpl(() => Promise.resolve('i am image'));
|
AssetServer.prototype.get.mockImplementation(() => Promise.resolve('i am image'));
|
||||||
|
|
||||||
server.processRequest(req, res);
|
server.processRequest(req, res);
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
|
@ -375,7 +375,7 @@ describe('processRequest', () => {
|
||||||
const res = {end: jest.fn(), writeHead: jest.fn(), setHeader: jest.fn()};
|
const res = {end: jest.fn(), writeHead: jest.fn(), setHeader: jest.fn()};
|
||||||
const mockData = 'i am image';
|
const mockData = 'i am image';
|
||||||
|
|
||||||
AssetServer.prototype.get.mockImpl(() => Promise.resolve(mockData));
|
AssetServer.prototype.get.mockImplementation(() => Promise.resolve(mockData));
|
||||||
|
|
||||||
server.processRequest(req, res);
|
server.processRequest(req, res);
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
|
@ -387,7 +387,7 @@ describe('processRequest', () => {
|
||||||
const req = {url: '/assets/imgs/%E4%B8%BB%E9%A1%B5/logo.png'};
|
const req = {url: '/assets/imgs/%E4%B8%BB%E9%A1%B5/logo.png'};
|
||||||
const res = {end: jest.fn(), setHeader: jest.fn()};
|
const res = {end: jest.fn(), setHeader: jest.fn()};
|
||||||
|
|
||||||
AssetServer.prototype.get.mockImpl(() => Promise.resolve('i am image'));
|
AssetServer.prototype.get.mockImplementation(() => Promise.resolve('i am image'));
|
||||||
|
|
||||||
server.processRequest(req, res);
|
server.processRequest(req, res);
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
|
|
|
@ -29,8 +29,8 @@ describe('Cache', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getting/setting', () => {
|
describe('getting/setting', () => {
|
||||||
pit('calls loader callback for uncached file', () => {
|
it('calls loader callback for uncached file', () => {
|
||||||
fs.stat.mockImpl((file, callback) => {
|
fs.stat.mockImplementation((file, callback) => {
|
||||||
callback(null, {
|
callback(null, {
|
||||||
mtime: {
|
mtime: {
|
||||||
getTime: () => {},
|
getTime: () => {},
|
||||||
|
@ -41,7 +41,7 @@ describe('Cache', () => {
|
||||||
var cache = new Cache({
|
var cache = new Cache({
|
||||||
cacheKey: 'cache',
|
cacheKey: 'cache',
|
||||||
});
|
});
|
||||||
var loaderCb = jest.genMockFn().mockImpl(() => Promise.resolve());
|
var loaderCb = jest.genMockFn().mockImplementation(() => Promise.resolve());
|
||||||
|
|
||||||
return cache
|
return cache
|
||||||
.get('/rootDir/someFile', 'field', loaderCb)
|
.get('/rootDir/someFile', 'field', loaderCb)
|
||||||
|
@ -50,8 +50,8 @@ describe('Cache', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('supports storing multiple fields', () => {
|
it('supports storing multiple fields', () => {
|
||||||
fs.stat.mockImpl((file, callback) => {
|
fs.stat.mockImplementation((file, callback) => {
|
||||||
callback(null, {
|
callback(null, {
|
||||||
mtime: {
|
mtime: {
|
||||||
getTime: () => {},
|
getTime: () => {},
|
||||||
|
@ -63,7 +63,7 @@ describe('Cache', () => {
|
||||||
cacheKey: 'cache',
|
cacheKey: 'cache',
|
||||||
});
|
});
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var loaderCb = jest.genMockFn().mockImpl(() =>
|
var loaderCb = jest.genMockFn().mockImplementation(() =>
|
||||||
Promise.resolve(index++)
|
Promise.resolve(index++)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ describe('Cache', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('gets the value from the loader callback', () => {
|
it('gets the value from the loader callback', () => {
|
||||||
fs.stat.mockImpl((file, callback) =>
|
fs.stat.mockImplementation((file, callback) =>
|
||||||
callback(null, {
|
callback(null, {
|
||||||
mtime: {
|
mtime: {
|
||||||
getTime: () => {},
|
getTime: () => {},
|
||||||
|
@ -89,7 +89,7 @@ describe('Cache', () => {
|
||||||
var cache = new Cache({
|
var cache = new Cache({
|
||||||
cacheKey: 'cache',
|
cacheKey: 'cache',
|
||||||
});
|
});
|
||||||
var loaderCb = jest.genMockFn().mockImpl(() =>
|
var loaderCb = jest.genMockFn().mockImplementation(() =>
|
||||||
Promise.resolve('lol')
|
Promise.resolve('lol')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -98,8 +98,8 @@ describe('Cache', () => {
|
||||||
.then(value => expect(value).toBe('lol'));
|
.then(value => expect(value).toBe('lol'));
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('caches the value after the first call', () => {
|
it('caches the value after the first call', () => {
|
||||||
fs.stat.mockImpl((file, callback) => {
|
fs.stat.mockImplementation((file, callback) => {
|
||||||
callback(null, {
|
callback(null, {
|
||||||
mtime: {
|
mtime: {
|
||||||
getTime: () => {},
|
getTime: () => {},
|
||||||
|
@ -110,7 +110,7 @@ describe('Cache', () => {
|
||||||
var cache = new Cache({
|
var cache = new Cache({
|
||||||
cacheKey: 'cache',
|
cacheKey: 'cache',
|
||||||
});
|
});
|
||||||
var loaderCb = jest.genMockFn().mockImpl(() =>
|
var loaderCb = jest.genMockFn().mockImplementation(() =>
|
||||||
Promise.resolve('lol')
|
Promise.resolve('lol')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -126,9 +126,9 @@ describe('Cache', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('clears old field when getting new field and mtime changed', () => {
|
it('clears old field when getting new field and mtime changed', () => {
|
||||||
var mtime = 0;
|
var mtime = 0;
|
||||||
fs.stat.mockImpl((file, callback) => {
|
fs.stat.mockImplementation((file, callback) => {
|
||||||
callback(null, {
|
callback(null, {
|
||||||
mtime: {
|
mtime: {
|
||||||
getTime: () => mtime++,
|
getTime: () => mtime++,
|
||||||
|
@ -139,7 +139,7 @@ describe('Cache', () => {
|
||||||
var cache = new Cache({
|
var cache = new Cache({
|
||||||
cacheKey: 'cache',
|
cacheKey: 'cache',
|
||||||
});
|
});
|
||||||
var loaderCb = jest.genMockFn().mockImpl(() =>
|
var loaderCb = jest.genMockFn().mockImplementation(() =>
|
||||||
Promise.resolve('lol' + mtime)
|
Promise.resolve('lol' + mtime)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ describe('Cache', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not cache rejections', () => {
|
it('does not cache rejections', () => {
|
||||||
fs.stat.mockImpl((file, callback) => {
|
fs.stat.mockImplementation((file, callback) => {
|
||||||
callback(null, {
|
callback(null, {
|
||||||
mtime: {
|
mtime: {
|
||||||
getTime: () => {},
|
getTime: () => {},
|
||||||
|
@ -196,11 +196,11 @@ describe('Cache', () => {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.existsSync.mockImpl(() => true);
|
fs.existsSync.mockImplementation(() => true);
|
||||||
|
|
||||||
fs.statSync.mockImpl(filePath => fileStats[filePath]);
|
fs.statSync.mockImplementation(filePath => fileStats[filePath]);
|
||||||
|
|
||||||
fs.readFileSync.mockImpl(() => JSON.stringify({
|
fs.readFileSync.mockImplementation(() => JSON.stringify({
|
||||||
'/rootDir/someFile': {
|
'/rootDir/someFile': {
|
||||||
metadata: {mtime: 22},
|
metadata: {mtime: 22},
|
||||||
data: {field: 'oh hai'},
|
data: {field: 'oh hai'},
|
||||||
|
@ -212,7 +212,7 @@ describe('Cache', () => {
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should load cache from disk', () => {
|
it('should load cache from disk', () => {
|
||||||
var cache = new Cache({
|
var cache = new Cache({
|
||||||
cacheKey: 'cache',
|
cacheKey: 'cache',
|
||||||
});
|
});
|
||||||
|
@ -233,8 +233,8 @@ describe('Cache', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('should not load outdated cache', () => {
|
it('should not load outdated cache', () => {
|
||||||
fs.stat.mockImpl((file, callback) =>
|
fs.stat.mockImplementation((file, callback) =>
|
||||||
callback(null, {
|
callback(null, {
|
||||||
mtime: {
|
mtime: {
|
||||||
getTime: () => {},
|
getTime: () => {},
|
||||||
|
@ -247,7 +247,7 @@ describe('Cache', () => {
|
||||||
var cache = new Cache({
|
var cache = new Cache({
|
||||||
cacheKey: 'cache',
|
cacheKey: 'cache',
|
||||||
});
|
});
|
||||||
var loaderCb = jest.genMockFn().mockImpl(() =>
|
var loaderCb = jest.genMockFn().mockImplementation(() =>
|
||||||
Promise.resolve('new value')
|
Promise.resolve('new value')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ describe('Cache', () => {
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var mtimes = [10, 20, 30];
|
var mtimes = [10, 20, 30];
|
||||||
|
|
||||||
fs.stat.mockImpl((file, callback) =>
|
fs.stat.mockImplementation((file, callback) =>
|
||||||
callback(null, {
|
callback(null, {
|
||||||
mtime: {
|
mtime: {
|
||||||
getTime: () => mtimes[index++],
|
getTime: () => mtimes[index++],
|
||||||
|
@ -303,7 +303,7 @@ describe('Cache', () => {
|
||||||
|
|
||||||
describe('check for cache presence', () => {
|
describe('check for cache presence', () => {
|
||||||
it('synchronously resolves cache presence', () => {
|
it('synchronously resolves cache presence', () => {
|
||||||
fs.stat.mockImpl((file, callback) =>
|
fs.stat.mockImplementation((file, callback) =>
|
||||||
callback(null, {
|
callback(null, {
|
||||||
mtime: {
|
mtime: {
|
||||||
getTime: () => {},
|
getTime: () => {},
|
||||||
|
@ -314,7 +314,7 @@ describe('Cache', () => {
|
||||||
var cache = new Cache({
|
var cache = new Cache({
|
||||||
cacheKey: 'cache',
|
cacheKey: 'cache',
|
||||||
});
|
});
|
||||||
var loaderCb = jest.genMockFn().mockImpl(() =>
|
var loaderCb = jest.genMockFn().mockImplementation(() =>
|
||||||
Promise.resolve('banana')
|
Promise.resolve('banana')
|
||||||
);
|
);
|
||||||
var file = '/rootDir/someFile';
|
var file = '/rootDir/someFile';
|
||||||
|
@ -331,7 +331,7 @@ describe('Cache', () => {
|
||||||
|
|
||||||
describe('invalidate', () => {
|
describe('invalidate', () => {
|
||||||
it('invalidates the cache per file or per-field', () => {
|
it('invalidates the cache per file or per-field', () => {
|
||||||
fs.stat.mockImpl((file, callback) =>
|
fs.stat.mockImplementation((file, callback) =>
|
||||||
callback(null, {
|
callback(null, {
|
||||||
mtime: {
|
mtime: {
|
||||||
getTime: () => {},
|
getTime: () => {},
|
||||||
|
@ -342,7 +342,7 @@ describe('Cache', () => {
|
||||||
var cache = new Cache({
|
var cache = new Cache({
|
||||||
cacheKey: 'cache',
|
cacheKey: 'cache',
|
||||||
});
|
});
|
||||||
var loaderCb = jest.genMockFn().mockImpl(() =>
|
var loaderCb = jest.genMockFn().mockImplementation(() =>
|
||||||
Promise.resolve('banana')
|
Promise.resolve('banana')
|
||||||
);
|
);
|
||||||
var file = '/rootDir/someFile';
|
var file = '/rootDir/someFile';
|
||||||
|
|
|
@ -15,12 +15,12 @@ const AssetModule = require('../AssetModule');
|
||||||
describe('AssetModule:', () => {
|
describe('AssetModule:', () => {
|
||||||
const defaults = {file: '/arbitrary'};
|
const defaults = {file: '/arbitrary'};
|
||||||
|
|
||||||
pit('has no dependencies by default', () => {
|
it('has no dependencies by default', () => {
|
||||||
return new AssetModule(defaults).getDependencies()
|
return new AssetModule(defaults).getDependencies()
|
||||||
.then(deps => expect(deps).toEqual([]));
|
.then(deps => expect(deps).toEqual([]));
|
||||||
});
|
});
|
||||||
|
|
||||||
pit('can be parametrized with dependencies', () => {
|
it('can be parametrized with dependencies', () => {
|
||||||
const dependencies = ['arbitrary', 'dependencies'];
|
const dependencies = ['arbitrary', 'dependencies'];
|
||||||
return new AssetModule({...defaults, dependencies}).getDependencies()
|
return new AssetModule({...defaults, dependencies}).getDependencies()
|
||||||
.then(deps => expect(deps).toEqual(dependencies));
|
.then(deps => expect(deps).toEqual(dependencies));
|
||||||
|
|
Loading…
Reference in New Issue