Skip to content

Commit 8b705e6

Browse files
committed
Use patched version of tmp + avoid using promisifyAll
promisifyAll alters the prototype of the passed object, which can lead to errors while executing the test case unitary. Instead use the already imported library tmp-promise
1 parent 8bdbe6b commit 8b705e6

File tree

13 files changed

+28
-49
lines changed

13 files changed

+28
-49
lines changed

app/server/declarations/tmp.d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

app/server/lib/ActiveDoc.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ import * as moment from 'moment-timezone';
148148
import fetch from 'node-fetch';
149149
import stream from 'node:stream';
150150
import path from 'path';
151-
import tmp from 'tmp';
152151

153152
import {ActionHistory} from './ActionHistory';
154153
import {ActionHistoryImpl} from './ActionHistoryImpl';
@@ -172,8 +171,6 @@ import sum = require('lodash/sum');
172171
import throttle = require('lodash/throttle');
173172
import without = require('lodash/without');
174173

175-
bluebird.promisifyAll(tmp);
176-
177174
const MAX_RECENT_ACTIONS = 100;
178175

179176
const DEFAULT_TIMEZONE = (process.versions as any).electron ? moment.tz.guess() : "UTC";

app/server/lib/DocPluginManager.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ import { GristServer } from 'app/server/lib/GristServer';
1616
import log from 'app/server/lib/log';
1717
import { SafePythonComponent } from 'app/server/lib/SafePythonComponent';
1818
import { UnsafeNodeComponent } from 'app/server/lib/UnsafeNodeComponent';
19-
import { promisifyAll } from 'bluebird';
2019
import * as fse from 'fs-extra';
2120
import * as path from 'path';
22-
import tmp from 'tmp';
23-
24-
25-
promisifyAll(tmp);
21+
import * as tmp from 'tmp-promise';
2622

2723
/**
2824
* Implements GristDocAPI interface.
@@ -196,7 +192,7 @@ export class DocPluginManager {
196192
}
197193

198194
private async _initialize(): Promise<void> {
199-
this._tmpDir = await tmp.dirAsync({ prefix: 'grist-tmp-', unsafeCleanup: true });
195+
this._tmpDir = (await tmp.dir({ prefix: 'grist-tmp-', unsafeCleanup: true })).path;
200196
for (const plugin of this._localPlugins) {
201197
try {
202198
// todo: once Comm has been replaced by grain-rpc, pluginInstance.rpc should forward '*' to client

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
"slugify": "1.6.6",
214214
"swagger-ui-dist": "5.11.0",
215215
"tar-stream": "^3.1.7",
216-
"tmp": "0.2.4",
216+
"tmp": "https://github.com/fflorent/node-tmp#fix-tmp-dir-with-dir",
217217
"tmp-promise": "1.0.5",
218218
"ts-interface-checker": "1.0.2",
219219
"typeorm": "0.3.17",

stubs/app/server/tmp.d.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/server/docTools.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {assert} from 'chai';
1717
import * as fse from 'fs-extra';
1818
import {tmpdir} from 'os';
1919
import * as path from 'path';
20-
import * as tmp from 'tmp';
20+
import * as tmp from 'tmp-promise';
2121

2222
tmp.setGracefulCleanup();
2323

@@ -168,12 +168,12 @@ export async function createDocManager(
168168
export async function createTmpDir(): Promise<string> {
169169
const tmpRootDir = process.env.TESTDIR || tmpdir();
170170
await fse.mkdirs(tmpRootDir);
171-
return fse.realpath(await tmp.dirAsync({
171+
return (await tmp.dir({
172172
dir: tmpRootDir,
173173
prefix: 'grist_test_',
174174
unsafeCleanup: true,
175175
keep: noCleanup,
176-
}));
176+
})).path;
177177
}
178178

179179
/**

test/server/lib/DocStorage.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
const assert = require('chai').assert;
22
const child_process = require('child_process');
33
const fs = require('fs');
4-
const tmp = require('tmp');
54

65
const Promise = require('bluebird');
76
Promise.promisifyAll(child_process);
87
Promise.promisifyAll(fs);
9-
Promise.promisifyAll(tmp);
108

119
const {ActionHistoryImpl} = require('app/server/lib/ActionHistoryImpl');
1210
const {DocStorage} = require('app/server/lib/DocStorage');
@@ -15,8 +13,6 @@ const marshal = require('app/common/marshal');
1513
const {createDocTools} = require('test/server/docTools');
1614
const testUtils = require('test/server/testUtils');
1715

18-
tmp.setGracefulCleanup();
19-
2016
describe('DocStorage', function() {
2117

2218
var docStorageManager;

test/server/lib/DocStorageManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {assert} from 'chai';
44
import * as fse from 'fs-extra';
55
import * as path from 'path';
6-
import * as tmp from 'tmp';
6+
import * as tmp from 'tmp-promise';
77

88
import {DocStorageManager} from 'app/server/lib/DocStorageManager';
99
import * as docUtils from 'app/server/lib/docUtils';
@@ -17,7 +17,7 @@ describe('DocStorageManager', function() {
1717
let docsRoot: string;
1818
let docStorageManager: DocStorageManager;
1919
before(async function() {
20-
const tmpDir = await tmp.dirAsync({ prefix: 'grist_test_', unsafeCleanup: true });
20+
const tmpDir = (await tmp.dir({ prefix: 'grist_test_', unsafeCleanup: true })).path;
2121
docsRoot = fse.realpathSync(tmpDir);
2222
docStorageManager = new DocStorageManager(docsRoot);
2323
});

test/server/lib/DocStorageMigrations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as fse from 'fs-extra';
77
import * as path from 'path';
88
import * as testUtils from 'test/server/testUtils';
99
import {assert} from 'test/server/testUtils';
10-
import * as tmp from 'tmp';
10+
import * as tmp from 'tmp-promise';
1111

1212
tmp.setGracefulCleanup();
1313
const execFileAsync = promisify(child_process.execFile);
@@ -20,7 +20,7 @@ describe('DocStorageMigrations', function() {
2020

2121
before(async function() {
2222
// Set Grist home to a temporary directory, and wipe it out on exit.
23-
let tmpDir = await tmp.dirAsync({ prefix: 'grist_test_', unsafeCleanup: true });
23+
let tmpDir = (await tmp.dir({ prefix: 'grist_test_', unsafeCleanup: true })).path;
2424
tmpDir = await fse.realpath(tmpDir);
2525
docStorageManager = new DocStorageManager(tmpDir);
2626
});

test/server/lib/SQLiteDB.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {assert} from 'chai';
22
import * as fse from 'fs-extra';
33
import {map, noop} from 'lodash';
44
import {join as pathJoin} from 'path';
5-
import * as tmp from 'tmp';
5+
import * as tmp from 'tmp-promise';
66

77
import {delay} from 'app/common/delay';
88
import {OpenMode, SchemaInfo, SQLiteDB} from 'app/server/lib/SQLiteDB';
@@ -13,17 +13,18 @@ tmp.setGracefulCleanup();
1313

1414
describe('SQLiteDB', function() {
1515
let tmpDir: string;
16+
let cleanup: () => void;
1617

1718
// Turn off logging for this test, and restore afterwards.
1819
testUtils.setTmpLogLevel('warn');
1920

2021
before(async function() {
2122
// Create a temporary directory, and wipe it out on exit.
22-
tmpDir = await tmp.dirAsync({ prefix: 'grist_test_SQLiteDB_', unsafeCleanup: true });
23+
({path: tmpDir, cleanup} = await tmp.dir({ prefix: 'grist_test_SQLiteDB_', unsafeCleanup: true }));
2324
});
2425

25-
after(async function() {
26-
await fse.remove(tmpDir);
26+
after(function() {
27+
cleanup();
2728
});
2829

2930
// Convenience helpers to make tests more concise and readable.

0 commit comments

Comments
 (0)