-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from jevancc/performance-improvement
Improvements on OriginalSource and ReplaceSource
- Loading branch information
Showing
3 changed files
with
82 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var should = require("should"); | ||
var OriginalSource = require("../lib/OriginalSource"); | ||
|
||
describe("OriginalSource", function() { | ||
it("should handle multiline string", function() { | ||
var source = new OriginalSource("Line1\n\nLine3\n", "file.js"); | ||
var resultText = source.source(); | ||
var resultMap = source.sourceAndMap({ | ||
columns: true | ||
}); | ||
var resultListMap = source.sourceAndMap({ | ||
columns: false | ||
}); | ||
|
||
resultText.should.be.eql("Line1\n\nLine3\n"); | ||
resultMap.source.should.be.eql(resultText); | ||
resultListMap.source.should.be.eql(resultText); | ||
resultListMap.map.file.should.be.eql(resultMap.map.file); | ||
resultListMap.map.version.should.be.eql(resultMap.map.version); | ||
resultMap.map.sources.should.be.eql(["file.js"]); | ||
resultListMap.map.sources.should.be.eql(resultMap.map.sources); | ||
resultMap.map.sourcesContent.should.be.eql(["Line1\n\nLine3\n"]); | ||
resultListMap.map.sourcesContent.should.be.eql(resultMap.map.sourcesContent); | ||
resultMap.map.mappings.should.be.eql("AAAA;;AAEA"); | ||
resultListMap.map.mappings.should.be.eql("AAAA;AACA;AACA;"); | ||
}); | ||
|
||
it("should handle empty string", function() { | ||
var source = new OriginalSource("", "file.js"); | ||
var resultText = source.source(); | ||
var resultMap = source.sourceAndMap({ | ||
columns: true | ||
}); | ||
var resultListMap = source.sourceAndMap({ | ||
columns: false | ||
}); | ||
|
||
resultText.should.be.eql(""); | ||
resultMap.source.should.be.eql(resultText); | ||
resultListMap.source.should.be.eql(resultText); | ||
resultListMap.map.file.should.be.eql(resultMap.map.file); | ||
resultListMap.map.version.should.be.eql(resultMap.map.version); | ||
resultMap.map.sources.should.be.eql([]); | ||
resultListMap.map.sources.should.be.eql(resultMap.map.sources); | ||
resultMap.map.mappings.should.be.eql(""); | ||
resultListMap.map.mappings.should.be.eql(""); | ||
}); | ||
|
||
it("should omit mappings for columns with node", function() { | ||
var source = new OriginalSource("Line1\n\nLine3\n", "file.js"); | ||
var resultMap = source.node({ | ||
columns: false | ||
}).toStringWithSourceMap({ | ||
file: "x" | ||
}).map.toJSON(); | ||
|
||
resultMap.mappings.should.be.eql("AAAA;AACA;AACA"); | ||
}); | ||
}); |