UNPKG

1.78 kBJavaScriptView Raw
1'use strict'
2
3const assert = require('assert')
4const makePromise = require('makepromise')
5const erase = require('../../src/erase')
6const wrote = require('../../src/wrote')
7const WroteContext = require('../context/WroteContext')
8
9const eraseTestSuite = {
10 context: WroteContext,
11 'should erase passed file': (ctx) => {
12 const file = ctx.tempFile
13 return wrote(file)
14 .then((ws) => {
15 return erase(ws)
16 })
17 .then((ws) => {
18 assert(ws.closed) // if node 6+, assert writable == false
19 assert.equal(ws.path, file)
20 })
21 .then(() => ctx.assertFileDoesNotExist(file))
22 },
23 'should erase temp file': (ctx) => {
24 let file
25 let writeStream
26
27 return wrote()
28 .then((ws) => {
29 writeStream = ws
30 file = writeStream.path
31 return erase(writeStream)
32 })
33 .then(() => {
34 assert(writeStream.closed)
35 assert.equal(writeStream.path, file)
36 })
37 .then(() => ctx.assertFileDoesNotExist(file))
38 },
39 'should erase file even if stream is closed': (ctx) => {
40 const file = ctx.tempFile
41 let writeStream
42 return wrote(file)
43 .then((ws) => {
44 writeStream = ws
45 return makePromise(writeStream.end.bind(writeStream))
46 })
47 .then(() => {
48 assert(writeStream.closed)
49 assert.equal(writeStream.path, file)
50 })
51 .then(() => ctx.assertFileExists(file))
52 .then(() => erase(writeStream))
53 .then(() => ctx.assertFileDoesNotExist(file))
54 },
55}
56
57module.exports = eraseTestSuite