forked from sintaxi/harp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
120 lines (103 loc) · 4.89 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var should = require("should")
var helpers = require("../lib/helpers")
var fse = require("fs-extra")
var path = require("path")
describe("helpers", function(){
describe("willCollide(projectPath, outputPath)", function(){
it("should collide if output path is /", function(done){
helpers.willCollide("/", "/").should.be.true
helpers.willCollide("/foo/bar/myproject", "/").should.be.true
helpers.willCollide("/foo/bar/myproject/", "/").should.be.true
done()
})
it("should not collide if output path is /output", function(done){
helpers.willCollide("/foo/bar/myproject", "/output").should.be.false
helpers.willCollide("/foo/bar/myproject", "/output/").should.be.false
helpers.willCollide("/foo/bar/myproject/", "/output/").should.be.false
helpers.willCollide("/foo/bar/myproject/", "/output").should.be.false
done()
})
it("should not collide if output path is in projectPath", function(done){
helpers.willCollide("/foo/bar/myproject", "/foo/bar/myproject/www").should.be.false
helpers.willCollide("/foo/bar/myproject/", "/foo/bar/myproject/www").should.be.false
helpers.willCollide("/foo/bar/myproject", "/foo/bar/myproject/www/").should.be.false
helpers.willCollide("/foo/bar/myproject/", "/foo/bar/myproject/www/").should.be.false
done()
})
it("should not collide if project path is one back and begins with underscore", function(done){
helpers.willCollide("/foo/bar/myproject", "/foo/bar").should.be.true
helpers.willCollide("/foo/bar/myproject/", "/foo/bar/").should.be.true
helpers.willCollide("/foo/bar/myproject", "/foo/bar/").should.be.true
helpers.willCollide("/foo/bar/myproject/", "/foo/bar").should.be.true
done()
})
})
describe("willAllow(projectPath, outputPath)", function(){
it("should not allow project to compile one directory back if source not starting with underscore", function(done){
helpers.willAllow("/foo/bar/myproject", "/foo/bar").should.be.false
helpers.willAllow("/foo/bar/myproject/", "/foo/bar/").should.be.false
helpers.willAllow("/foo/bar/myproject", "/foo/bar/").should.be.false
helpers.willAllow("/foo/bar/myproject/", "/foo/bar").should.be.false
done()
})
it("should allow project to compile one directory back if source directory starts with underscore", function(done){
helpers.willAllow("/foo/bar/_myproject", "/foo/bar").should.be.true
helpers.willAllow("/foo/bar/_myproject/", "/foo/bar/").should.be.true
helpers.willAllow("/foo/bar/_myproject", "/foo/bar/").should.be.true
helpers.willAllow("/foo/bar/_myproject/", "/foo/bar").should.be.true
done()
})
it("should not allow project to compile one directory back if source directory starts with underscore", function(done){
helpers.willAllow("/foo/bar/_myproject", "/foo").should.be.false
helpers.willAllow("/foo/_bar/myproject", "/foo").should.be.false
helpers.willAllow("/foo/_bar/_myproject", "/foo").should.be.false
done()
})
})
describe("setup(projectPath)", function(){
it("should detect framework style", function(done){
var cfg = helpers.setup(path.join(__dirname, "apps", "app-style-framework"))
cfg.should.have.property("config")
cfg.should.have.property("projectPath")
cfg.should.have.property("publicPath")
done()
})
it("should detect root style", function(done){
var cfg = helpers.setup(path.join(__dirname, "apps", "app-style-root"))
cfg.should.have.property("config")
cfg.should.have.property("projectPath")
cfg.should.have.property("publicPath")
cfg.publicPath.should.eql(cfg.projectPath)
done()
})
it("should defautl to root style", function(done){
var cfg = helpers.setup(path.join(__dirname, "apps", "app-style-implicit"))
cfg.should.have.property("config")
cfg.should.have.property("projectPath")
cfg.should.have.property("publicPath")
cfg.publicPath.should.eql(cfg.projectPath)
done()
})
})
describe("prime(outputPath)", function(){
before(function(done){
fse.mkdirp(path.join(__dirname, "temp"), function(){
fse.mkdirSync(path.join(__dirname, "temp", "myproj"))
fse.mkdirSync(path.join(__dirname, "temp", "foo"))
fse.writeFileSync(path.join(__dirname, "temp", "bar"), "hello bar")
done()
})
})
it("should only remove directories that do not begin with underscore", function(done){
helpers.prime(path.join(__dirname, "temp"), { ignore: "myproj" }, function(error){
fse.existsSync(path.join(__dirname, "temp", "myproj")).should.be.true
fse.existsSync(path.join(__dirname, "temp", "foo")).should.be.false
fse.existsSync(path.join(__dirname, "temp", "bar")).should.be.false
done()
})
})
after(function(done){
fse.remove(path.join(__dirname, "temp"), done)
})
})
})