Skip to content

Commit

Permalink
Separate exported modules and internal code (#1397)
Browse files Browse the repository at this point in the history
Reorganize the `src/` directory following [1], creating a clear
separation between code that is meant for exporting (modules) and only
for internal use (internal). This is purely refactoring, no functional
change should have occured.

Besides making the `src/` directory hopefully clearer, it also
simplifies configuration files, and especially improves clarity on what
tests should do what - unit tests test what is internal, other tests
test everything and thus focus on the modules instead.

--
1. 44e16b2
  • Loading branch information
ericcornelissen authored Jan 27, 2024
1 parent bf3c195 commit 9b9b9aa
Show file tree
Hide file tree
Showing 46 changed files with 76 additions and 78 deletions.
4 changes: 1 addition & 3 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ flags:
unit:
carryforward: true
paths:
- src/
ignore:
- src/modules/
- src/internal/

ignore:
- script/**/*
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/fuzz-bash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
paths:
- .github/workflows/fuzz-bash.yml
- .github/workflows/reusable-fuzz.yml
- src/unix/bash.js
- src/internal/unix/bash.js
- test/fuzz/**
push:
paths:
- .github/workflows/fuzz-bash.yml
- .github/workflows/reusable-fuzz.yml
- src/unix/bash.js
- src/internal/unix/bash.js
- test/fuzz/**
branches:
- main
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/fuzz-cmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
paths:
- .github/workflows/fuzz-cmd.yml
- .github/workflows/reusable-fuzz.yml
- src/win/cmd.js
- src/internal/win/cmd.js
- test/fuzz/**
push:
paths:
- .github/workflows/fuzz-cmd.yml
- .github/workflows/reusable-fuzz.yml
- src/win/cmd.js
- src/internal/win/cmd.js
- test/fuzz/**
branches:
- main
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/fuzz-csh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
paths:
- .github/workflows/fuzz-csh.yml
- .github/workflows/reusable-fuzz.yml
- src/unix/csh.js
- src/internal/unix/csh.js
- test/fuzz/**
push:
paths:
- .github/workflows/fuzz-csh.yml
- .github/workflows/reusable-fuzz.yml
- src/unix/csh.js
- src/internal/unix/csh.js
- test/fuzz/**
branches:
- main
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/fuzz-dash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
paths:
- .github/workflows/fuzz-dash.yml
- .github/workflows/reusable-fuzz.yml
- src/unix/dash.js
- src/internal/unix/dash.js
- test/fuzz/**
push:
paths:
- .github/workflows/fuzz-dash.yml
- .github/workflows/reusable-fuzz.yml
- src/unix/dash.js
- src/internal/unix/dash.js
- test/fuzz/**
branches:
- main
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/fuzz-no-shell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ on:
paths:
- .github/workflows/fuzz-no-shell.yml
- .github/workflows/reusable-fuzz.yml
- src/unix/no-shell.js
- src/win/no-shell.js
- src/internal/unix/no-shell.js
- src/internal/win/no-shell.js
- test/fuzz/**
push:
paths:
- .github/workflows/fuzz-no-shell.yml
- .github/workflows/reusable-fuzz.yml
- src/unix/no-shell.js
- src/win/no-shell.js
- src/internal/unix/no-shell.js
- src/internal/win/no-shell.js
- test/fuzz/**
branches:
- main
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/fuzz-powershell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
paths:
- .github/workflows/fuzz-powershell.yml
- .github/workflows/reusable-fuzz.yml
- src/win/powershell.js
- src/internal/win/powershell.js
- test/fuzz/**
push:
paths:
- .github/workflows/fuzz-powershell.yml
- .github/workflows/reusable-fuzz.yml
- src/win/powershell.js
- src/internal/win/powershell.js
- test/fuzz/**
branches:
- main
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/fuzz-zsh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
paths:
- .github/workflows/fuzz-zsh.yml
- .github/workflows/reusable-fuzz.yml
- src/unix/zsh.js
- src/internal/unix/zsh.js
- test/fuzz/**
push:
paths:
- .github/workflows/fuzz-zsh.yml
- .github/workflows/reusable-fuzz.yml
- src/unix/zsh.js
- src/internal/unix/zsh.js
- test/fuzz/**
branches:
- main
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ The unit tests aim to test isolated units of code, typically a single function.
All unit test suites go into the `test/unit/` folder. You can run unit tests
using the command `npm run test:unit`.

The structure of the unit tests folder roughly follows that of the `src/`
folder. Each file in `src/` is represented by a folder in the test structure,
where files represent individual units within the respective file in `src/`.
The structure of the unit tests folder roughly follows that of `src/internal/`.
Each file in `src/internal/` is represented by a folder in the test structure,
where files represent individual units within the respective file.

When writing unit tests, aim to test one thing at the time. Correspondingly, the
test title should describe what is being tested - not how it is tested, or what
Expand Down
4 changes: 2 additions & 2 deletions config/c8/e2e-unix.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"**/*.{cjs,d.cts,d.ts}",
"src/modules/stateless.js",
"src/modules/testing.js",
"src/win/",
"src/win.js"
"src/internal/win/",
"src/internal/win.js"
],
"check-coverage": false,
"reports-dir": "_reports/coverage/e2e",
Expand Down
4 changes: 2 additions & 2 deletions config/c8/e2e-win.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"**/*.{cjs,d.cts,d.ts}",
"src/modules/stateless.js",
"src/modules/testing.js",
"src/unix/",
"src/unix.js"
"src/internal/unix/",
"src/internal/unix.js"
],
"check-coverage": false,
"reports-dir": "_reports/coverage/e2e",
Expand Down
6 changes: 5 additions & 1 deletion config/c8/integration-unix.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"all": true,
"include": ["src/"],
"exclude": ["**/*.{cjs,d.cts,d.ts}", "src/win/", "src/win.js"],
"exclude": [
"**/*.{cjs,d.cts,d.ts}",
"src/internal/win/",
"src/internal/win.js"
],
"check-coverage": false,
"reports-dir": "_reports/coverage/integration",
"reporter": ["lcov", "text"]
Expand Down
6 changes: 5 additions & 1 deletion config/c8/integration-win.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"all": true,
"include": ["src/"],
"exclude": ["**/*.{cjs,d.cts,d.ts}", "src/unix/", "src/unix.js"],
"exclude": [
"**/*.{cjs,d.cts,d.ts}",
"src/internal/unix/",
"src/internal/unix.js"
],
"check-coverage": false,
"reports-dir": "_reports/coverage/integration",
"reporter": ["lcov", "text"]
Expand Down
4 changes: 2 additions & 2 deletions config/c8/unit.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"all": true,
"include": ["src/"],
"exclude": ["**/*.{cjs,d.cts,d.ts}", "src/modules/*"],
"include": ["src/internal/"],
"exclude": ["**/*.{cjs,d.cts,d.ts}"],
"check-coverage": true,
"branches": 100,
"functions": 100,
Expand Down
11 changes: 2 additions & 9 deletions config/eslint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,6 @@ overrides:
# Source code
- files:
- src/**/*.js
- index.js
- stateless.js
- testing.js
rules:
jsdoc/check-values:
- error
Expand Down Expand Up @@ -774,9 +771,5 @@ ignorePatterns:
- .temp/
- node_modules/
- script/maybe-run.js
- src/modules/index.cjs
- src/modules/index.d.cts
- src/modules/stateless.cjs
- src/modules/stateless.d.cts
- src/modules/testing.cjs
- src/modules/testing.d.cts
- src/modules/*.cjs
- src/modules/*.d.cts
2 changes: 1 addition & 1 deletion config/stryker/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export default {
coverageAnalysis: "perTest",
inPlace: false,
mutate: ["src/modules/*.js"],
mutate: ["src/modules/**/*.js"],
testRunner: "tap",
tap: {
testFiles: ["test/integration/**/*.test.js"],
Expand Down
3 changes: 1 addition & 2 deletions config/stryker/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
export default {
coverageAnalysis: "perTest",
inPlace: false,
mutate: ["src/**/*.js"],
ignorePatterns: ["src/modules/**/*"],
mutate: ["src/internal/**/*.js"],
testRunner: "tap",
tap: {
testFiles: ["test/unit/**/*.test.js"],
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import os from "node:os";
import process from "node:process";

import { parseOptions } from "../options.js";
import { getHelpersByPlatform } from "../platforms.js";
import { checkedToString } from "../reflection.js";
import { parseOptions } from "../internal/options.js";
import { getHelpersByPlatform } from "../internal/platforms.js";
import { checkedToString } from "../internal/reflection.js";

/**
* A class to escape user-controlled inputs to shell commands to prevent shell
Expand Down
2 changes: 1 addition & 1 deletion src/modules/testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @license MPL-2.0
*/

import { checkedToString } from "../reflection.js";
import { checkedToString } from "../internal/reflection.js";

/**
* A list of example shell injection strings to test whether or not a function
Expand Down
2 changes: 1 addition & 1 deletion test/unit/executables/resolve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import sinon from "sinon";

import { arbitrary } from "./_.js";

import { resolveExecutable } from "../../../src/executables.js";
import { resolveExecutable } from "../../../src/internal/executables.js";

test.before((t) => {
const executable = "/bin/sh";
Expand Down
4 changes: 2 additions & 2 deletions test/unit/options/parse-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import sinon from "sinon";

import { arbitrary } from "./_.js";

import { resolveExecutable } from "../../../src/executables.js";
import { noShell, parseOptions } from "../../../src/options.js";
import { resolveExecutable } from "../../../src/internal/executables.js";
import { noShell, parseOptions } from "../../../src/internal/options.js";

const arbitraryInput = () =>
fc
Expand Down
6 changes: 3 additions & 3 deletions test/unit/platforms/get-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import * as fc from "fast-check";

import { arbitrary, constants } from "./_.js";

import { getHelpersByPlatform } from "../../../src/platforms.js";
import * as unix from "../../../src/unix.js";
import * as win from "../../../src/win.js";
import { getHelpersByPlatform } from "../../../src/internal/platforms.js";
import * as unix from "../../../src/internal/unix.js";
import * as win from "../../../src/internal/win.js";

const unixPlatforms = [
constants.osAix,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/reflection/checked-to-string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as fc from "fast-check";

import { arbitrary, constants } from "./_.js";

import { checkedToString } from "../../../src/reflection.js";
import { checkedToString } from "../../../src/internal/reflection.js";

testProp("strings", [fc.string()], (t, value) => {
const result = checkedToString(value);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/reflection/has-own.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { testProp } from "@fast-check/ava";
import * as fc from "fast-check";

import { hasOwn } from "../../../src/reflection.js";
import { hasOwn } from "../../../src/internal/reflection.js";

testProp("not present", [fc.object(), fc.string()], (t, object, property) => {
const actual = hasOwn(object, property);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/reflection/is-string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { testProp } from "@fast-check/ava";
import * as fc from "fast-check";

import { isString } from "../../../src/reflection.js";
import { isString } from "../../../src/internal/reflection.js";

testProp("strings", [fc.string()], (t, value) => {
const result = isString(value);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/unix/csh.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TextDecoder } from "node:util";
import { testProp } from "@fast-check/ava";
import * as fc from "fast-check";

import * as csh from "../../../src/unix/csh.js";
import * as csh from "../../../src/internal/unix/csh.js";

const textDecoder = new TextDecoder("utf-8", { fatal: true });

Expand Down
14 changes: 7 additions & 7 deletions test/unit/unix/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import sinon from "sinon";

import { arbitrary, constants } from "./_.js";

import * as unix from "../../../src/unix.js";
import * as bash from "../../../src/unix/bash.js";
import * as csh from "../../../src/unix/csh.js";
import * as dash from "../../../src/unix/dash.js";
import * as nosh from "../../../src/unix/no-shell.js";
import * as zsh from "../../../src/unix/zsh.js";
import { noShell } from "../../../src/options.js";
import * as unix from "../../../src/internal/unix.js";
import * as bash from "../../../src/internal/unix/bash.js";
import * as csh from "../../../src/internal/unix/csh.js";
import * as dash from "../../../src/internal/unix/dash.js";
import * as nosh from "../../../src/internal/unix/no-shell.js";
import * as zsh from "../../../src/internal/unix/zsh.js";
import { noShell } from "../../../src/internal/options.js";

const shells = [
{ module: bash, shellName: constants.binBash },
Expand Down
2 changes: 1 addition & 1 deletion test/unit/unix/no-shell.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { testProp } from "@fast-check/ava";
import * as fc from "fast-check";

import * as nosh from "../../../src/unix/no-shell.js";
import * as nosh from "../../../src/internal/unix/no-shell.js";

testProp("quote function", [fc.string()], (t, arg) => {
const expected = {
Expand Down
10 changes: 5 additions & 5 deletions test/unit/unix/shells.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import * as fc from "fast-check";

import { constants, fixtures, macros } from "./_.js";

import * as bash from "../../../src/unix/bash.js";
import * as csh from "../../../src/unix/csh.js";
import * as dash from "../../../src/unix/dash.js";
import * as nosh from "../../../src/unix/no-shell.js";
import * as zsh from "../../../src/unix/zsh.js";
import * as bash from "../../../src/internal/unix/bash.js";
import * as csh from "../../../src/internal/unix/csh.js";
import * as dash from "../../../src/internal/unix/dash.js";
import * as nosh from "../../../src/internal/unix/no-shell.js";
import * as zsh from "../../../src/internal/unix/zsh.js";

const shells = {
[null]: nosh,
Expand Down
10 changes: 5 additions & 5 deletions test/unit/win/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import sinon from "sinon";

import { arbitrary, constants } from "./_.js";

import * as win from "../../../src/win.js";
import * as cmd from "../../../src/win/cmd.js";
import * as nosh from "../../../src/win/no-shell.js";
import * as powershell from "../../../src/win/powershell.js";
import { noShell } from "../../../src/options.js";
import * as win from "../../../src/internal/win.js";
import * as cmd from "../../../src/internal/win/cmd.js";
import * as nosh from "../../../src/internal/win/no-shell.js";
import * as powershell from "../../../src/internal/win/powershell.js";
import { noShell } from "../../../src/internal/options.js";

const shells = [
{ module: cmd, shellName: "cmd.exe" },
Expand Down
Loading

0 comments on commit 9b9b9aa

Please sign in to comment.