MCPcopy Index your code
hub / github.com/restify/node-restify / testNoAppendPath

Function testNoAppendPath

test/plugins/static.test.js:125–181  ·  view source on GitHub ↗
(done, testDefault, tmpDir, regex, staticFile)

Source from the content-addressed store, hash-verified

123 }
124
125 function testNoAppendPath(done, testDefault, tmpDir, regex, staticFile) {
126 var staticContent = '{"content": "abcdefg"}';
127 var staticObj = JSON.parse(staticContent);
128 var testDir = 'public';
129 var testFileName = 'index.json';
130 var routeName = 'GET wildcard';
131 var tmpPath = path.join(__dirname, '../', tmpDir);
132
133 mkdirp(tmpPath, function(err) {
134 assert.ifError(err);
135 DIRS_TO_DELETE.push(tmpPath);
136 var folderPath = path.join(tmpPath, testDir);
137
138 mkdirp(folderPath, function(err2) {
139 assert.ifError(err2);
140
141 DIRS_TO_DELETE.push(folderPath);
142 var file = path.join(folderPath, testFileName);
143
144 fs.writeFile(file, staticContent, function(err3) {
145 assert.ifError(err3);
146 FILES_TO_DELETE.push(file);
147 var p = '/' + testDir + '/' + testFileName;
148 var opts = { directory: folderPath };
149 opts.appendRequestPath = false;
150
151 if (staticFile) {
152 opts.file = testFileName;
153 }
154
155 if (testDefault) {
156 p = '/' + testDir + '/';
157 opts.default = testFileName;
158 routeName += ' with default';
159 }
160
161 SERVER.get(
162 {
163 path: '/' + testDir + '/*',
164 name: routeName
165 },
166 restify.plugins.serveStatic(opts)
167 );
168
169 CLIENT.get(p, function(err4, req, res, obj) {
170 assert.ifError(err4);
171 assert.equal(
172 res.headers['cache-control'],
173 'public, max-age=3600'
174 );
175 assert.deepEqual(obj, staticObj);
176 done();
177 });
178 });
179 });
180 });
181 }
182

Callers 1

static.test.jsFile · 0.85

Calls 1

doneFunction · 0.85

Tested by

no test coverage detected