|
| 1 | +var should = require('should'); |
| 2 | +var utils = require('../src/utils'); |
| 3 | + |
| 4 | +describe('Utils', function() { |
| 5 | + var getRequireString = utils.getRequireString; |
| 6 | + |
| 7 | + var path = 'path'; |
| 8 | + var name = 'name'; |
| 9 | + |
| 10 | + describe('getRequireString', function() { |
| 11 | + it('should return a require statement', function() { |
| 12 | + getRequireString(path, name).should.eql('require(\'path\')[\'name\']'); |
| 13 | + }); |
| 14 | + }); |
| 15 | + |
| 16 | + describe('getSyncLoader', function() { |
| 17 | + var getSyncLoader = utils.getSyncLoader; |
| 18 | + |
| 19 | + it('should return a synchronous require loadChildren statement', function() { |
| 20 | + var result = [ |
| 21 | + 'loadChildren: function() {\n', |
| 22 | + ' return ' + getRequireString(path, name) + ';\n', |
| 23 | + '}' |
| 24 | + ]; |
| 25 | + |
| 26 | + getSyncLoader('path', 'name').should.eql(result.join('')); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + describe('getRequireLoader', function() { |
| 31 | + var getRequireLoader = utils.getRequireLoader; |
| 32 | + |
| 33 | + it('should return an asynchronous require loadChildren statement', function() { |
| 34 | + var result = [ |
| 35 | + 'loadChildren: () => new Promise(function (resolve) {\n', |
| 36 | + ' (require as any).ensure([], function (require) {\n', |
| 37 | + ' resolve(' + getRequireString(path, name) + ');\n', |
| 38 | + ' });\n', |
| 39 | + '})' |
| 40 | + ]; |
| 41 | + |
| 42 | + getRequireLoader('path', 'name').should.eql(result.join('')); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('getSystemLoader', function() { |
| 47 | + var getSystemLoader = utils.getSystemLoader; |
| 48 | + |
| 49 | + it('should return an asynchronous System.import loadChildren statement', function() { |
| 50 | + var result = [ |
| 51 | + 'loadChildren: () => System.import(\'' + path + '\')\n', |
| 52 | + ' .then(function(module) {\n', |
| 53 | + ' return module[\'' + name + '\'];\n', |
| 54 | + ' })' |
| 55 | + ]; |
| 56 | + |
| 57 | + getSystemLoader('path', 'name').should.eql(result.join('')); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + describe('normalizeFilePath', function() { |
| 62 | + var pmock = require('pmock'); |
| 63 | + var normalizeFilePath = utils.normalizeFilePath; |
| 64 | + var env; |
| 65 | + |
| 66 | + describe('for windows os', function() { |
| 67 | + beforeEach(function() { |
| 68 | + env = pmock.platform('win32'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should replace backslashes with forward slashes', function() { |
| 72 | + normalizeFilePath('./path').should.eql('.\\\\path'); |
| 73 | + }); |
| 74 | + |
| 75 | + afterEach(function() { |
| 76 | + env.reset(); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + describe('for non-windows os', function() { |
| 81 | + beforeEach(function() { |
| 82 | + env = pmock.platform('posix'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should not replace backslashes', function() { |
| 86 | + normalizeFilePath('./path').should.eql('./path'); |
| 87 | + }); |
| 88 | + |
| 89 | + afterEach(function() { |
| 90 | + env.reset(); |
| 91 | + }); |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + describe('getFilename', function() { |
| 96 | + var getFilename = utils.getFilename; |
| 97 | + |
| 98 | + it('should return the filename for a given path without an extension', function() { |
| 99 | + getFilename('path/to/module.ngfactory.ts').should.eql('module.ngfactory'); |
| 100 | + }); |
| 101 | + }); |
| 102 | +}); |
0 commit comments