|
| 1 | +var RawModule = require("../lib/RawModule"); |
| 2 | +var OriginalSource = require("webpack-sources").OriginalSource; |
| 3 | +var RawSource = require("webpack-sources").RawSource; |
| 4 | +var RequestShortener = require("../lib/RequestShortener"); |
| 5 | +var should = require("should"); |
| 6 | +var path = require("path") |
| 7 | + |
| 8 | +describe("RawModule", function() { |
| 9 | + var myRawModule; |
| 10 | + |
| 11 | + before(function() { |
| 12 | + var source = 'sourceStr attribute'; |
| 13 | + var identifier = 'identifierStr attribute'; |
| 14 | + var readableIdentifier = 'readableIdentifierStr attribute'; |
| 15 | + myRawModule = new RawModule(source, identifier, readableIdentifier); |
| 16 | + }); |
| 17 | + |
| 18 | + describe('identifier', function() { |
| 19 | + it('returns value for identifierStr attribute', function() { |
| 20 | + should(myRawModule.identifier()).be.exactly('identifierStr attribute'); |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + describe('size', function() { |
| 25 | + it('returns value for sourceStr attribute\'s length property', function() { |
| 26 | + var sourceStrLength = myRawModule.sourceStr.length; |
| 27 | + should(myRawModule.size()).be.exactly(sourceStrLength); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('readableIdentifier', function() { |
| 32 | + it('returns result of calling provided requestShortener\'s shorten method\ |
| 33 | + on readableIdentifierStr attribute', function() { |
| 34 | + var requestShortener = new RequestShortener(path.resolve()); |
| 35 | + should.exist(myRawModule.readableIdentifier(requestShortener)); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + describe('needRebuild', function() { |
| 40 | + it('returns false', function() { |
| 41 | + should(myRawModule.needRebuild()).be.false(); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('build', function() { |
| 46 | + it('sets builtTime attribute to current time value in milliseconds', function() { |
| 47 | + myRawModule.build('', '', '', '', () => { |
| 48 | + undefined |
| 49 | + }) |
| 50 | + var currentTime = new Date().getTime(); |
| 51 | + myRawModule.builtTime.should.be.exactly(currentTime); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + describe('source', function() { |
| 56 | + it('returns a new OriginalSource instance with sourceStr attribute and\ |
| 57 | + return value of identifier() function provided as constructor arguments', |
| 58 | + function() { |
| 59 | + var originalSource = new OriginalSource(myRawModule.sourceStr, myRawModule.identifier()); |
| 60 | + myRawModule.useSourceMap = true; |
| 61 | + myRawModule.source().should.match(originalSource); |
| 62 | + }); |
| 63 | + |
| 64 | + it('returns a new RawSource instance with sourceStr attribute provided\ |
| 65 | + as constructor argument if useSourceMap is falsey', function() { |
| 66 | + var rawSource = new RawSource(myRawModule.sourceStr); |
| 67 | + myRawModule.useSourceMap = false; |
| 68 | + myRawModule.source().should.match(rawSource); |
| 69 | + }); |
| 70 | + }); |
| 71 | +}); |
0 commit comments