forked from sintaxi/harp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
131 lines (113 loc) · 5.37 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
121
122
123
124
125
126
127
128
129
130
131
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 default 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()
})
it("should replace values like $foo with process.env.foo", function(done){
process.env.HARP_BASIC_AUTH = "jabberwocky:skrillex"
var cfg = helpers.setup(path.join(__dirname, "apps", "envy"))
cfg.should.have.property("config")
cfg.should.have.property("projectPath")
cfg.should.have.property("publicPath")
cfg.config.should.have.property("basicAuth", "jabberwocky:skrillex")
cfg.config.should.not.have.property("optionalThing")
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)
})
})
})