From 64774c5ebface08a7c787b5a5c036454c93f8140 Mon Sep 17 00:00:00 2001 From: Nikolai Kolodziej <7687617+kldzj@users.noreply.github.com> Date: Sat, 12 Feb 2022 07:32:37 +0100 Subject: [PATCH] fix #1505 and add test (#1511) --- prelude/bootstrap.js | 4 ++-- test/test-1505/.gitignore | 1 + test/test-1505/files/test.txt | 0 test/test-1505/main.js | 29 +++++++++++++++++++++++++++++ test/test-1505/package.json | 6 ++++++ test/test-1505/stat.js | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 test/test-1505/.gitignore create mode 100644 test/test-1505/files/test.txt create mode 100644 test/test-1505/main.js create mode 100644 test/test-1505/package.json create mode 100644 test/test-1505/stat.js diff --git a/prelude/bootstrap.js b/prelude/bootstrap.js index 6704873e4..777c806fb 100644 --- a/prelude/bootstrap.js +++ b/prelude/bootstrap.js @@ -1679,12 +1679,12 @@ function payloadFileSync(pointer) { // this one use promisify on purpose fs.promises.readdir = util.promisify(fs.readdir); fs.promises.copyFile = util.promisify(fs.copyFile); + fs.promises.stat = util.promisify(fs.stat); + fs.promises.lstat = util.promisify(fs.lstat); /* fs.promises.read = util.promisify(fs.read); fs.promises.realpath = util.promisify(fs.realpath); - fs.promises.stat = util.promisify(fs.stat); - fs.promises.lstat = util.promisify(fs.lstat); fs.promises.fstat = util.promisify(fs.fstat); fs.promises.access = util.promisify(fs.access); */ diff --git a/test/test-1505/.gitignore b/test/test-1505/.gitignore new file mode 100644 index 000000000..abbca5c97 --- /dev/null +++ b/test/test-1505/.gitignore @@ -0,0 +1 @@ +run-time diff --git a/test/test-1505/files/test.txt b/test/test-1505/files/test.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test/test-1505/main.js b/test/test-1505/main.js new file mode 100644 index 000000000..e0a66d2ef --- /dev/null +++ b/test/test-1505/main.js @@ -0,0 +1,29 @@ +#!/usr/bin/env node + +'use strict'; + +const path = require('path'); +const assert = require('assert'); +const utils = require('../utils.js'); + +assert(!module.parent); +assert(__dirname === process.cwd()); + +const target = process.argv[2] || 'host'; +const input = './stat.js'; +const output = './run-time/test-output.exe'; + +utils.mkdirp.sync(path.dirname(output)); +utils.pkg.sync(['--target', target, '--output', output, '.']); + +let left, right; +left = utils.spawn.sync('node', [path.basename(input)], { + cwd: path.dirname(input), +}); + +right = utils.spawn.sync(output, [], { + cwd: path.dirname(input), +}); + +assert.strictEqual(left, right); +utils.vacuum.sync(path.dirname(output)); diff --git a/test/test-1505/package.json b/test/test-1505/package.json new file mode 100644 index 000000000..1327fd87e --- /dev/null +++ b/test/test-1505/package.json @@ -0,0 +1,6 @@ +{ + "bin": "stat.js", + "pkg": { + "scripts": "files/*" + } +} diff --git a/test/test-1505/stat.js b/test/test-1505/stat.js new file mode 100644 index 000000000..b9f23436a --- /dev/null +++ b/test/test-1505/stat.js @@ -0,0 +1,32 @@ +'use strict'; + +const path = require('path'); +const util = require('util'); +const fs = require('fs'); +let fsp; + +try { + fsp = require('fs/promises'); +} catch (_) { + fsp = require('fs').promises; +} + +const filePath = path.join(__dirname, 'files/test.txt'); + +async function test() { + for (const key of ['stat', 'lstat']) { + console.log(key, 'callback'); + const promisified = util.promisify(fs[key]); + console.log(serialize(await promisified(filePath))); + + console.log(key, 'promise'); + console.log(serialize(await fsp[key](filePath))); + } +} + +function serialize(result) { + if (!result) return null; + return `${result.size} ${result.mode}`; +} + +test();