Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix tests #41

Merged
merged 4 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@1f99358870fe1c846a3ccba386cc2b2246836776 # v2.2.1
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Checkout repository
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@04df1262e6247151b5ac09cd2c303ac36ad3f62b # v2.2.9
uses: github/codeql-action/init@83f0fe6c4988d98a455712a27f0255212bba9bd4 # v2.3.6
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -63,7 +63,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@04df1262e6247151b5ac09cd2c303ac36ad3f62b # v2.2.9
uses: github/codeql-action/autobuild@83f0fe6c4988d98a455712a27f0255212bba9bd4 # v2.3.6

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -76,6 +76,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@04df1262e6247151b5ac09cd2c303ac36ad3f62b # v2.2.9
uses: github/codeql-action/analyze@83f0fe6c4988d98a455712a27f0255212bba9bd4 # v2.3.6
with:
category: "/language:${{matrix.language}}"
category: "/language:${{matrix.language}}"
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Node.js CI

on:
push:
branches: main
branches: [main]
pull_request:

permissions:
Expand All @@ -17,11 +17,11 @@ jobs:
fail-fast: false
steps:
- name: Harden Runner
uses: step-security/harden-runner@1f99358870fe1c846a3ccba386cc2b2246836776 # v2.2.1
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@1f99358870fe1c846a3ccba386cc2b2246836776 # v2.2.1
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: "Checkout code"
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.3.0 # v3.1.0
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
persist-credentials: false

Expand Down Expand Up @@ -72,6 +72,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@04df1262e6247151b5ac09cd2c303ac36ad3f62b # v2.2.9
uses: github/codeql-action/upload-sarif@83f0fe6c4988d98a455712a27f0255212bba9bd4 # v2.3.6
with:
sarif_file: results.sarif
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# fs-walk

![version](https://img.shields.io/badge/dynamic/json.svg?style=for-the-badge&url=https://raw.githubusercontent.com/NodeSecure/fs-walk/master/package.json&query=$.version&label=Version)
![version](https://img.shields.io/badge/dynamic/json.svg?style=for-the-badge&url=https://raw.githubusercontent.com/NodeSecure/fs-walk/main/package.json&query=$.version&label=Version)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg?style=for-the-badge)](https://github.com/NodeSecure/fs-walk/graphs/commit-activity)
[![OpenSSF
Scorecard](https://api.securityscorecards.dev/projects/github.com/NodeSecure/fs-walk/badge?style=for-the-badge)](https://api.securityscorecards.dev/projects/github.com/NodeSecure/fs-walk)
[![mit](https://img.shields.io/github/license/NodeSecure/fs-walk.svg?style=for-the-badge)](https://github.com/NodeSecure/fs-walk/blob/master/LICENSE)
[![mit](https://img.shields.io/github/license/NodeSecure/fs-walk.svg?style=for-the-badge)](https://github.com/NodeSecure/fs-walk/blob/main/LICENSE)
![build](https://img.shields.io/github/actions/workflow/status/NodeSecure/fs-walk/node.js.yml?style=for-the-badge)

Modern FileSystem (fs) utilities to lazy walk directories Asynchronously (but also Synchronously). Under the hood the code has been created using ES6 Generators.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Import Node.js dependencies
// Import Node.js Dependencies
import { opendir } from "fs/promises";
import { readdirSync } from "fs";
import path from "path";
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
},
"homepage": "https://github.com/NodeSecure/fs-walk#readme",
"devDependencies": {
"@nodesecure/eslint-config": "^1.5.0",
"c8": "^7.12.0"
"@nodesecure/eslint-config": "^1.7.0",
"c8": "^8.0.0"
},
"type": "module"
}
34 changes: 14 additions & 20 deletions test/walk.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
// Import Node.js Dependencies
import test from "node:test";
import assert from "node:assert"
import assert from "node:assert";
import path from "node:path";
import { fileURLToPath } from "node:url";

// Require Node.js Dependencies
import path from "path";
import { fileURLToPath } from "url";

// Require Internal Dependencies
// Import Internal Dependencies
import { walk, walkSync } from "../index.js";

// CONSTANTS
const __dirname = path.dirname(fileURLToPath(import.meta.url));

const kRootLocation = path.join(__dirname, "..");
const kFixturesDir = path.join(__dirname, "fixtures");
const kExpectedJSFiles = ["index.js", "test/walk.js"].map((fileLocation) =>
path.normalize(fileLocation)
);
const kExpectedJSFiles = ["index.js", "test/walk.js"].map((fileLocation) => path.normalize(fileLocation));

test("should return all JavaScript files of the project (Asynchronously)", async (t) => {
test("should return all JavaScript files of the project (Asynchronously)", async() => {
const files = [];
const options = { extensions: new Set([".js"]) };

Expand All @@ -30,31 +27,28 @@ test("should return all JavaScript files of the project (Asynchronously)", async
}
}

assert.deepEqual(files, kExpectedJSFiles);
assert.deepEqual(files.sort(), kExpectedJSFiles);
});

test("should return all JavaScript files of the project (Synchronously)", async (t) => {
test("should return all JavaScript files of the project (Synchronously)", async() => {
const options = { extensions: new Set([".js"]) };

const files = [...walkSync(kRootLocation, options)]
.filter(([dirent]) => dirent.isFile())
.map(([, absoluteFileLocation]) =>
path.relative(kRootLocation, absoluteFileLocation)
);
.map(([, absoluteFileLocation]) => path.relative(kRootLocation, absoluteFileLocation));

assert.deepEqual(files, kExpectedJSFiles);
});

test("should return all files in the fixtures directory", async (t) => {
test("should return all files in the fixtures directory", async() => {
const files = [...walkSync(kFixturesDir)]
.filter(([dirent]) => dirent.isFile())
.map(([, absoluteFileLocation]) =>
path.relative(kRootLocation, absoluteFileLocation)
);
.map(([, absoluteFileLocation]) => path.relative(kRootLocation, absoluteFileLocation));

const expectedFiles = [
"test/fixtures/foobar.txt",
"test/fixtures/test.md",
"test/fixtures/test.md"
].map((fileLocation) => path.normalize(fileLocation));

assert.deepEqual(files, expectedFiles);
});