1 | "use strict";
|
2 |
|
3 | var chai = require("chai"),
|
4 | expect = chai.expect,
|
5 | ncp = require("ncp").ncp,
|
6 | grunt = require("grunt"),
|
7 | JsBeautifierTask = require("../lib/jsbeautifier"),
|
8 | createMockTask = require("./mockTask");
|
9 | chai.use(require('chai-fs'));
|
10 |
|
11 |
|
12 | describe("JsBeautifier: rc file test", function() {
|
13 | var mockTask;
|
14 |
|
15 | beforeEach(function(done) {
|
16 | grunt.file.mkdir("tmp/rcFile");
|
17 | ncp("test/fixtures/configFile", "tmp/rcFile", done);
|
18 | });
|
19 |
|
20 | afterEach(function() {
|
21 | mockTask = null;
|
22 | grunt.file.delete("tmp");
|
23 | grunt.file.delete(".jsbeautifierrc");
|
24 | });
|
25 |
|
26 | function assertBeautifiedFile(actualFile, expectedFile) {
|
27 | var actual = "tmp/rcFile/" + actualFile,
|
28 | expected = grunt.file.read("tmp/rcFile/" + expectedFile);
|
29 |
|
30 | expect(actual).to.have.content(expected, "should beautify js " + actualFile + " using config file");
|
31 | }
|
32 |
|
33 | it("beautification of js, css & html file using settings from rc file", function(done) {
|
34 | var task;
|
35 | ncp("tmp/rcFile/jsbeautifyrc.json", ".jsbeautifierrc", function() {
|
36 |
|
37 | mockTask = createMockTask({}, ["tmp/rcFile/test.js", "tmp/rcFile/test.css", "tmp/rcFile/test.html"], function() {
|
38 | assertBeautifiedFile("test.js", "expected/test_expected.js");
|
39 | assertBeautifiedFile("test.css", "expected/test_expected.css");
|
40 | assertBeautifiedFile("test.html", "expected/test_expected.html");
|
41 | done();
|
42 | });
|
43 |
|
44 | task = new JsBeautifierTask(mockTask);
|
45 | console.log('Running task');
|
46 | task.run();
|
47 | });
|
48 | });
|
49 |
|
50 | it("beautification of js, css & html file using settings from flat rc file", function(done) {
|
51 | var task;
|
52 | ncp("tmp/rcFile/jsbeautifyrc_flat.json", ".jsbeautifierrc", function() {
|
53 |
|
54 | mockTask = createMockTask({}, ["tmp/rcFile/test.js", "tmp/rcFile/test.css", "tmp/rcFile/test.html"], function() {
|
55 | assertBeautifiedFile("test.js", "expected/test_expected.js");
|
56 | assertBeautifiedFile("test.css", "expected/test_expected.css");
|
57 | assertBeautifiedFile("test.html", "expected/test_expected.html");
|
58 | done();
|
59 | });
|
60 |
|
61 | task = new JsBeautifierTask(mockTask);
|
62 | task.run();
|
63 | });
|
64 | });
|
65 |
|
66 | it("beautification of js, css & html file using settings from rc file and gruntfile", function(done) {
|
67 | var task;
|
68 | ncp("tmp/rcFile/jsbeautifyrc_flat.json", ".jsbeautifierrc", function() {
|
69 |
|
70 | mockTask = createMockTask({
|
71 | css: {
|
72 | indentSize: 5
|
73 | },
|
74 | html: {
|
75 | indentSize: 7
|
76 | }
|
77 | }, ["tmp/rcFile/test.js", "tmp/rcFile/test.css", "tmp/rcFile/test.html"], function() {
|
78 | assertBeautifiedFile("test.js", "expected/withGruntFileOptions/test_expected.js");
|
79 | assertBeautifiedFile("test.css", "expected/withGruntFileOptions/test_expected.css");
|
80 | assertBeautifiedFile("test.html", "expected/withGruntFileOptions/test_expected.html");
|
81 | done();
|
82 | });
|
83 |
|
84 | task = new JsBeautifierTask(mockTask);
|
85 | task.run();
|
86 | });
|
87 | });
|
88 | });
|