Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempting to get node 12 passing.
Browse files Browse the repository at this point in the history
Tzrlk committed Apr 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 731860b commit a754fdd
Showing 4 changed files with 65 additions and 51 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Node.js tests
name: tests

on:
workflow_dispatch:
@@ -18,12 +18,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 8
- 10
- 12
- 14
- 16
- 18
- 20
steps:

- name: checkout
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -39,6 +39,6 @@
"q": "^1.5.1"
},
"engines": {
"node": ">=10"
"node": ">=12"
}
}
87 changes: 48 additions & 39 deletions test/integration/file.js
Original file line number Diff line number Diff line change
@@ -16,11 +16,20 @@
*
*/

const assert = require('assert');
const fs = require('fs');
const file = require('../../lib/utils/file');
const { existsSync, readdirSync, rmSync, symlinkSync, unlinkSync, writeFileSync } = require('fs');
const { assertFileMode, testRequiresWindowsElevation, ensureDirs } = require('./helpers');
const { suite, setup, test } = require('mocha');
const assert = require('assert');
const file = require('../../lib/utils/file');

// Shim to support older node versions
const rmF = rmSync
? (path) => rmSync(path, { force: true })
: (path) => {
if (existsSync(path)) {
unlinkSync(path);
}
};

suite('fileUtils', function () {

@@ -33,13 +42,13 @@ suite('fileUtils', function () {

test('with dir', function () {
file.mkdirP('foo');
assert.ok(fs.existsSync('foo'));
assert.ok(existsSync('foo'));
ensureDirs(false, 'foo');
});

test('with subdir', function () {
file.mkdirP('foo/bar/baz/qux');
assert.ok(fs.existsSync('foo/bar/baz/qux'));
assert.ok(existsSync('foo/bar/baz/qux'));
ensureDirs(false, 'foo');
});

@@ -50,48 +59,48 @@ suite('fileUtils', function () {
test('with subdir', function () {
ensureDirs('foo/bar/baz/qux');
file.rmRf('foo/bar');
assert.deepStrictEqual(fs.readdirSync('foo'), []);
assert.strictEqual(fs.existsSync('foo/bar'), false);
assert.deepStrictEqual(readdirSync('foo'), []);
assert.strictEqual(existsSync('foo/bar'), false);
ensureDirs(false, 'foo');
});

test('with symlink subdir', function () {
testRequiresWindowsElevation(this);

ensureDirs('foo', 'bar');
fs.writeFileSync('foo/hello.txt', 'hello, it\'s me');
fs.symlinkSync('../foo', 'bar/foo');
writeFileSync('foo/hello.txt', 'hello, it\'s me');
symlinkSync('../foo', 'bar/foo');

file.rmRf('bar');

// Make sure the bar directory was successfully deleted
assert.strictEqual(fs.existsSync('bar'), false);
assert.strictEqual(existsSync('bar'), false);

// Make sure that the file inside the linked folder wasn't deleted
assert.strictEqual(fs.existsSync('foo/hello.txt'), true);
assert.strictEqual(existsSync('foo/hello.txt'), true);

// Cleanup
fs.unlinkSync('foo/hello.txt');
unlinkSync('foo/hello.txt');
ensureDirs(false, 'foo', 'bar');
});

test('with symlinked dir', function () {
testRequiresWindowsElevation(this);

ensureDirs('foo');
fs.writeFileSync('foo/hello.txt', 'hello!');
fs.symlinkSync('foo', 'bar');
writeFileSync('foo/hello.txt', 'hello!');
symlinkSync('foo', 'bar');

file.rmRf('bar');

// Make sure the bar directory was successfully deleted
assert.strictEqual(fs.existsSync('bar'), false);
assert.strictEqual(existsSync('bar'), false);

// Make sure that the file inside the linked folder wasn't deleted
assert.strictEqual(fs.existsSync('foo/hello.txt'), true);
assert.strictEqual(existsSync('foo/hello.txt'), true);

// Cleanup
fs.unlinkSync('foo/hello.txt');
unlinkSync('foo/hello.txt');
ensureDirs(false, 'foo', 'bar');
});

@@ -101,10 +110,10 @@ suite('fileUtils', function () {

test('with same name and different directory', function () {
ensureDirs('foo', false, 'bar');
fs.writeFileSync('foo/bar.txt', 'w00t');
writeFileSync('foo/bar.txt', 'w00t');

file.cpR('foo', 'bar');
assert.ok(fs.existsSync('bar/bar.txt'));
assert.ok(existsSync('bar/bar.txt'));

ensureDirs(false, 'foo', 'bar');
});
@@ -117,61 +126,61 @@ suite('fileUtils', function () {

test('rename via copy in directory', function () {
ensureDirs('foo');
fs.writeFileSync('foo/bar.txt', 'w00t');
writeFileSync('foo/bar.txt', 'w00t');

file.cpR('foo/bar.txt', 'foo/baz.txt');
assert.ok(fs.existsSync('foo/baz.txt'));
assert.ok(existsSync('foo/baz.txt'));

ensureDirs(false, 'foo');
});

test('rename via copy in base', function () {
fs.writeFileSync('bar.txt', 'w00t');
writeFileSync('bar.txt', 'w00t');

file.cpR('bar.txt', 'baz.txt');
assert.ok(fs.existsSync('baz.txt'));
assert.ok(existsSync('baz.txt'));

fs.rmSync('bar.txt');
fs.rmSync('baz.txt');
rmF('bar.txt');
rmF('baz.txt');
});

test('keeps file mode', function () {
[ 0o750, 0o744 ].forEach((mode) => {
fs.writeFileSync('bar.txt', 'w00t', { mode: mode });
writeFileSync('bar.txt', 'w00t', { mode: mode });

file.cpR('bar.txt', 'baz.txt');
assertFileMode('baz.txt', mode);

fs.rmSync('bar.txt');
fs.rmSync('baz.txt');
rmF('bar.txt');
rmF('baz.txt');
});
});

test('keeps file mode when overwriting with preserveMode', function () {
fs.writeFileSync('bar.txt', 'w00t', {mode: 0o755});
fs.writeFileSync('baz.txt', 'w00t!', {mode: 0o744});
writeFileSync('bar.txt', 'w00t', {mode: 0o755});
writeFileSync('baz.txt', 'w00t!', {mode: 0o744});

file.cpR('bar.txt', 'baz.txt', {silent: true, preserveMode: true});
assertFileMode('baz.txt', 0o755);

fs.rmSync('bar.txt');
fs.rmSync('baz.txt');
rmF('bar.txt');
rmF('baz.txt');
});

test('does not keep file mode when overwriting', function () {
fs.writeFileSync('bar.txt', 'w00t', {mode: 0o766});
fs.writeFileSync('baz.txt', 'w00t!', {mode: 0o744});
writeFileSync('bar.txt', 'w00t', {mode: 0o766});
writeFileSync('baz.txt', 'w00t!', {mode: 0o744});

file.cpR('bar.txt', 'baz.txt');
assertFileMode('baz.txt', 0o744);

fs.rmSync('bar.txt');
fs.rmSync('baz.txt');
rmF('bar.txt');
rmF('baz.txt');
});

test('copies file mode recursively', function () {
ensureDirs('foo', false, 'baz');
fs.writeFileSync('foo/bar.txt', 'w00t', {mode: 0o740});
writeFileSync('foo/bar.txt', 'w00t', {mode: 0o740});

file.cpR('foo', 'baz');
assertFileMode('baz/bar.txt', 0o740);
@@ -181,8 +190,8 @@ suite('fileUtils', function () {

test('keeps file mode recursively', function () {
ensureDirs('foo', 'baz/foo');
fs.writeFileSync('foo/bar.txt', 'w00t', {mode: 0o740});
fs.writeFileSync('baz/foo/bar.txt', 'w00t!', {mode: 0o755});
writeFileSync('foo/bar.txt', 'w00t', {mode: 0o740});
writeFileSync('baz/foo/bar.txt', 'w00t!', {mode: 0o755});

file.cpR('foo', 'baz', {silent: true, preserveMode: true});
assertFileMode('baz/foo/bar.txt', 0o740);
22 changes: 14 additions & 8 deletions test/integration/helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const { join, normalize } = require("path");
const os = require("os");
const assert = require("assert");
const { existsSync, statSync } = require('fs');
const { existsSync, statSync, mkdirSync, rmSync, rmdirSync } = require('fs');
const { exec, execFileSync, spawnSync, execSync } = require("child_process");
const fs = require("fs");

// Shim to support older nodejs versions.
const rmRf = rmSync
? (path) => rmSync(path, { recursive: true, force: true })
: (path) => {
if (existsSync(path)) {
rmdirSync(path);
}
};

const jakeCliPath = normalize(join(__dirname, '..', '..', 'bin', 'cli.js'));

@@ -154,11 +162,9 @@ const helpers = new (function () {
this.ensureDirs = function (...items) {

// Remove all the directories first, to avoid messing up creation later.
for (const item of items) {
if (typeof item === 'string') {
fs.rmSync(item, { recursive: true, force: true });
}
}
items
.filter((item) => typeof item === 'string')
.forEach((item) => rmRf(item));

let create = true;
let mode = undefined;
@@ -180,7 +186,7 @@ const helpers = new (function () {

case "string": {
if (create) {
fs.mkdirSync(item, {recursive: true, mode: mode});
mkdirSync(item, { recursive: true, mode: mode });
}
break;
}

0 comments on commit a754fdd

Please sign in to comment.