Skip to content

Commit cec357c

Browse files
committed
test: pass process.env.DEBUG to ms instances
1 parent ed968f6 commit cec357c

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

test/index.js

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ function fixture(p) {
1818
const googleHumansTxt =
1919
"Google is built by a large team of engineers, designers, researchers, robots, and others in many different sites across the globe. It is updated continuously, and built with more tools and technologies than we can shake a stick at. If you'd like to help us out, see careers.google.com.\n"
2020

21+
function ms(p) {
22+
return Metalsmith(fixture(p)).env('DEBUG', process.env.DEBUG)
23+
}
2124
describe('@metalsmith/requests', function () {
2225
let server
2326

@@ -44,7 +47,7 @@ describe('@metalsmith/requests', function () {
4447
})
4548

4649
it('should not crash the metalsmith build when using default options', function (done) {
47-
Metalsmith(fixture('default'))
50+
ms('default')
4851
.use(plugin())
4952
.build((err) => {
5053
if (err) done(err)
@@ -81,41 +84,41 @@ describe('@metalsmith/requests', function () {
8184
})
8285

8386
it("out.key && !out.path: should assign a response's data to global metadata", function (done) {
84-
const ms = Metalsmith(fixture('default'))
87+
const m = ms('default')
8588
const files = {}
8689
const config = {
8790
url: 'https://www.google.com/humans.txt',
8891
out: { key: 'googlehumans' }
8992
}
90-
plugin(config)(files, ms, (err) => {
93+
plugin(config)(files, m, (err) => {
9194
if (err) done(err)
92-
assert.strictEqual(ms.metadata().googlehumans, googleHumansTxt)
95+
assert.strictEqual(m.metadata().googlehumans, googleHumansTxt)
9396
done()
9497
})
9598
})
9699

97100
it("!out.key && out.path: should assign a response's data to a file's 'contents' by default", function (done) {
98-
const ms = Metalsmith(fixture('default'))
101+
const m = ms('default')
99102
const files = { 'test.md': {} }
100103
const config = {
101104
url: 'https://www.google.com/humans.txt',
102105
out: { path: 'test.md' }
103106
}
104-
plugin(config)(files, ms, (err) => {
107+
plugin(config)(files, m, (err) => {
105108
if (err) done(err)
106109
assert.strictEqual(files['test.md'].contents.toString(), googleHumansTxt)
107110
done()
108111
})
109112
})
110113

111114
it("out.key && out.path: should assign a response's data to file metadata at files[out.path][out.key]", function (done) {
112-
const ms = Metalsmith(fixture('default'))
115+
const m = ms('default')
113116
const files = { 'test.md': { layout: 'default.njk' } }
114117
const config = {
115118
url: 'https://www.google.com/humans.txt',
116119
out: { path: 'test.md', key: 'request' }
117120
}
118-
plugin(config)(files, ms, (err) => {
121+
plugin(config)(files, m, (err) => {
119122
if (err) done(err)
120123
assert.strictEqual(files['test.md'].request, googleHumansTxt)
121124
assert.strictEqual(files['test.md'].layout, 'default.njk')
@@ -125,7 +128,7 @@ describe('@metalsmith/requests', function () {
125128
})
126129

127130
it('should treat files with a "request" key in metadata as entries', function (done) {
128-
Metalsmith(fixture('implicit-entries'))
131+
ms('implicit-entries')
129132
.use(plugin())
130133
.build((err) => {
131134
if (err) return done(err)
@@ -135,7 +138,7 @@ describe('@metalsmith/requests', function () {
135138
})
136139

137140
it('should replace path placeholders in out and url options accordingly', function (done) {
138-
Metalsmith(fixture('placeholders'))
141+
ms('placeholders')
139142
.use(
140143
plugin({
141144
url: 'https://webketje.com/assets/css/:filename.css',
@@ -151,7 +154,7 @@ describe('@metalsmith/requests', function () {
151154
})
152155

153156
it('should allow specifying shorthands', function (done) {
154-
Metalsmith(fixture('single-request-option'))
157+
ms('single-request-option')
155158
.use(
156159
plugin({
157160
url: 'https://webketje.com/assets/css/main.css',
@@ -166,8 +169,8 @@ describe('@metalsmith/requests', function () {
166169
})
167170

168171
it("should auto-parse a response as JSON when the response's Content-Type header is application/json", function (done) {
169-
const ms = Metalsmith(fixture('default'))
170-
ms.use(
172+
const m = ms('default')
173+
m.use(
171174
plugin({
172175
url: 'https://api.github.com/repos/metalsmith/drafts/contents/README.md',
173176
out: { key: 'readme' },
@@ -182,7 +185,7 @@ describe('@metalsmith/requests', function () {
182185
).process((err) => {
183186
if (err) done(err)
184187
assert.strictEqual(
185-
ms.metadata().readme.download_url,
188+
m.metadata().readme.download_url,
186189
'https://raw.githubusercontent.com/metalsmith/drafts/main/README.md'
187190
)
188191
done()
@@ -200,8 +203,8 @@ describe('@metalsmith/requests', function () {
200203
}
201204
}
202205
}`
203-
const ms = Metalsmith(fixture('default'))
204-
ms.use(
206+
const m = ms('default')
207+
m.use(
205208
plugin({
206209
url: 'https://api.github.com/graphql',
207210
out: { key: 'sassreadme' },
@@ -216,7 +219,7 @@ describe('@metalsmith/requests', function () {
216219
).process((err) => {
217220
if (err) done(err)
218221
assert.strictEqual(
219-
ms.metadata().sassreadme.data.repository.object.text.slice(0, 39),
222+
m.metadata().sassreadme.data.repository.object.text.slice(0, 39),
220223
'# @metalsmith/sass\n\nA Metalsmith plugin'
221224
)
222225
done()
@@ -225,7 +228,7 @@ describe('@metalsmith/requests', function () {
225228

226229
describe('should throw error', function () {
227230
it('"unsupported_protocol" when the protocol is not supported', function (done) {
228-
Metalsmith(fixture('default'))
231+
ms('default')
229232
.use(
230233
plugin({
231234
url: 'ftp://bad-protocol.com',
@@ -239,7 +242,7 @@ describe('@metalsmith/requests', function () {
239242
})
240243

241244
it('"ERR_INVALID_URL" when the URL is invalid', function (done) {
242-
Metalsmith(fixture('default'))
245+
ms('default')
243246
.use(
244247
plugin({
245248
url: 'random-invalid',
@@ -257,7 +260,7 @@ describe('@metalsmith/requests', function () {
257260
})
258261

259262
it('"invalid_http_method" when the HTTP method is invalid', function (done) {
260-
Metalsmith(fixture('default'))
263+
ms('default')
261264
.use(
262265
plugin({
263266
url: 'http://bad-httpmethod.com',
@@ -274,7 +277,7 @@ describe('@metalsmith/requests', function () {
274277
})
275278

276279
it('"invalid_outconfig" when the outconfig is invalid', function (done) {
277-
Metalsmith(fixture('default'))
280+
ms('default')
278281
.use(
279282
plugin({
280283
url: 'http://bad-outoption.com',
@@ -288,7 +291,7 @@ describe('@metalsmith/requests', function () {
288291
})
289292

290293
it('"invalid_outconfig" when the outconfig is of the wrong type', function (done) {
291-
Metalsmith(fixture('default'))
294+
ms('default')
292295
.use(
293296
plugin({
294297
url: 'http://bad-outoption.com',
@@ -305,7 +308,7 @@ describe('@metalsmith/requests', function () {
305308
if (!process.env.GITHUB_TOKEN) {
306309
this.skip()
307310
}
308-
Metalsmith(fixture('default'))
311+
ms('default')
309312
.use(
310313
plugin({
311314
url: 'https://graphql.github.com/graphql',
@@ -327,16 +330,17 @@ describe('@metalsmith/requests', function () {
327330
})
328331

329332
it('"invalid_json" when the response has Content-Type: application/json and is malformed', function (done) {
330-
const ms = Metalsmith(fixture('default'))
331-
ms.use(
332-
plugin({
333-
url: 'http://localhost:3000',
334-
out: { key: 'googlehumans' }
333+
ms('default')
334+
.use(
335+
plugin({
336+
url: 'http://localhost:3000',
337+
out: { key: 'googlehumans' }
338+
})
339+
)
340+
.process((err) => {
341+
assert.strictEqual(err.name, 'invalid_json')
342+
done()
335343
})
336-
).process((err) => {
337-
assert.strictEqual(err.name, 'invalid_json')
338-
done()
339-
})
340344
})
341345
})
342346
})

0 commit comments

Comments
 (0)