|
| 1 | +import { join } from 'path'; |
| 2 | + |
| 3 | +import { optimizationLoader } from './optimization-loader-impl'; |
| 4 | +import * as helpers from '../util/helpers'; |
| 5 | +import { FileCache } from '../util/file-cache'; |
| 6 | + |
| 7 | +describe('optimization loader impl', () => { |
| 8 | + describe('optimizationLoader', () => { |
| 9 | + it('should not cache files not in srcDir or ionicAngularDir', () => { |
| 10 | + const appDir = join('some', 'fake', 'path', 'myApp'); |
| 11 | + const srcDir = join(appDir, 'src'); |
| 12 | + const ionicAngularDir = join(appDir, 'node_modules', 'ionic-angular'); |
| 13 | + const fileCache = new FileCache(); |
| 14 | + const context = { |
| 15 | + srcDir: srcDir, |
| 16 | + ionicAngularDir: ionicAngularDir, |
| 17 | + fileCache: fileCache |
| 18 | + }; |
| 19 | + |
| 20 | + const spy = jasmine.createSpy('callback'); |
| 21 | + const webpackContext = { |
| 22 | + cacheable: () => {}, |
| 23 | + async: () => spy, |
| 24 | + resourcePath: join(appDir, 'node_modules', '@angular', 'core', 'index.js') |
| 25 | + }; |
| 26 | + |
| 27 | + spyOn(helpers, helpers.getContext.name).and.returnValue(context); |
| 28 | + |
| 29 | + optimizationLoader('someSource', {}, webpackContext); |
| 30 | + |
| 31 | + expect(fileCache.getAll().length).toEqual(0); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should cache files in the ionicAngularDir', () => { |
| 35 | + const appDir = join('some', 'fake', 'path', 'myApp'); |
| 36 | + const srcDir = join(appDir, 'src'); |
| 37 | + const ionicAngularDir = join(appDir, 'node_modules', 'ionic-angular'); |
| 38 | + const fileCache = new FileCache(); |
| 39 | + const context = { |
| 40 | + srcDir: srcDir, |
| 41 | + ionicAngularDir: ionicAngularDir, |
| 42 | + fileCache: fileCache |
| 43 | + }; |
| 44 | + |
| 45 | + const spy = jasmine.createSpy('callback'); |
| 46 | + const webpackContext = { |
| 47 | + cacheable: () => {}, |
| 48 | + async: () => spy, |
| 49 | + resourcePath: join(ionicAngularDir, 'index.js') |
| 50 | + }; |
| 51 | + |
| 52 | + spyOn(helpers, helpers.getContext.name).and.returnValue(context); |
| 53 | + |
| 54 | + const knownSource = 'someSource'; |
| 55 | + optimizationLoader(knownSource, {}, webpackContext); |
| 56 | + |
| 57 | + expect(fileCache.getAll().length).toEqual(1); |
| 58 | + expect(fileCache.get(webpackContext.resourcePath).path).toEqual(webpackContext.resourcePath); |
| 59 | + expect(fileCache.get(webpackContext.resourcePath).content).toEqual(knownSource); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should cache files in the srcDir', () => { |
| 63 | + const appDir = join('some', 'fake', 'path', 'myApp'); |
| 64 | + const srcDir = join(appDir, 'src'); |
| 65 | + const ionicAngularDir = join(appDir, 'node_modules', 'ionic-angular'); |
| 66 | + const fileCache = new FileCache(); |
| 67 | + const context = { |
| 68 | + srcDir: srcDir, |
| 69 | + ionicAngularDir: ionicAngularDir, |
| 70 | + fileCache: fileCache |
| 71 | + }; |
| 72 | + |
| 73 | + const spy = jasmine.createSpy('callback'); |
| 74 | + const webpackContext = { |
| 75 | + cacheable: () => {}, |
| 76 | + async: () => spy, |
| 77 | + resourcePath: join(srcDir, 'pages', 'page-one.ts') |
| 78 | + }; |
| 79 | + |
| 80 | + spyOn(helpers, helpers.getContext.name).and.returnValue(context); |
| 81 | + |
| 82 | + const knownSource = 'someSource'; |
| 83 | + optimizationLoader(knownSource, {}, webpackContext); |
| 84 | + |
| 85 | + expect(fileCache.getAll().length).toEqual(1); |
| 86 | + expect(fileCache.get(webpackContext.resourcePath).path).toEqual(webpackContext.resourcePath); |
| 87 | + expect(fileCache.get(webpackContext.resourcePath).content).toEqual(knownSource); |
| 88 | + }); |
| 89 | + }); |
| 90 | +}); |
0 commit comments