Skip to content

Commit

Permalink
test: registry-mock (#198)
Browse files Browse the repository at this point in the history
* test: fix snapshot

* test: filter out index files temporarily

* chore: install registry-mock

* chore(just): add pnpm to test

* feat: create registry-mock crate

* feat(registry-mock): expose get_or_init instead

* refactor: local static

* feat(testing-utils): add_mocked_registry

* refactor: rename new to init

* fix: enable_all

* refactor: use

* feat: add ending /

* fix: must be "localhost"

* feat(registry-mock): use portpicker

* feat(registry-mock): share a single instance

* feat(testing-utils): stop skipping index files

* test(cli/install): use registry-mock

* fix: forgot to save

* fix: forgot increment

* fix: used to wrong syntax

* feat(registry-mock): use advisory-lock

* fix: save anchor before early exit

* fix: drop before delete

* tmp: stored

* refactor: remove unused import

* fix: truncate the file

* feat: use try_lock

* feat(registry-mock): separate lock from anchor

* refactor: use RAII pattern

* fix(registry-mock): user_count

* refactor: rename user_count to ref_count

* fix: kill groups

* fix(registry-mock): ref_count

* chore(git): revert broken fix

This reverts commit 8c0ba7b.

* fix(registry-mock): use sysinfo to kill

* fix(registry-mock): kill algorithm

* feat(registry-mock): recurse regardless

* feat(registry-mock): use reverse recursion instead

* refactor: reduce complexity

* refactor: remove unnecessary mod declarations

* refactor: marks some struct as must_use

* test(cli/add): use registry-mock

* test(pnpm-compatibility): use registry-mock

* refactor: remove unused items

* docs: correction

* chore(license): allow MPL-2.0

* chore(license): allow Unlicense

* fix(registry-mock): failure on few threads

* chore: move pnpm install to just

* ci: cache pnpm

* fix(test): kill leftovers

* fix(test): allow delete to fail

* fix(ci): Install just

* fix(test): don't kill leftovers

This reverts commit ef78d8c.

* refactor: move some types to their own mods

* refactor: move port_to_url

* refactor: make listen lazy

* refactor: rename `listen` to `url`

* refactor: use qualified path

* refactor: store port as u16

* feat(registry-mock): PreparedRegistryInfo

* refactor: remove unnecessary async

* refactor: move init code

* refactor: define lib

* feat(registry-mock): bin

* refactor: call just test

* ci: prepare a server

* feat(registry-mock): unique prepared

* docs(registry-mock): cli

* feat(registry-mock/cli): locations of log files

* docs(mocked-registry): important items

* docs(registry-mock): ignore bin

* style: taplo fmt

* docs(readme): instruction to run test

* refactor: move registry-mock to tasks

* ci(codecov): fix

* feat(registry-mock): bump max_retries
  • Loading branch information
KSXGitHub authored Nov 17, 2023
1 parent 078359e commit f802fdf
Show file tree
Hide file tree
Showing 32 changed files with 3,412 additions and 429 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ jobs:
run_install: false
standalone: true

- name: Cache pnpm
uses: actions/cache@v3
with:
key: ci-pnpm-${{ matrix.os }}
path: |
${{ env.PNPM_HOME }}/store/v3
${{ env.HOME }}/.local/share/pnpm/store/v3
timeout-minutes: 1
continue-on-error: true

- name: Clippy
run: cargo clippy --locked -- -D warnings

Expand All @@ -52,18 +62,28 @@ jobs:
RUSTDOCFLAGS: '-D warnings'
run: cargo doc

- name: Install just
uses: taiki-e/install-action@just

- name: Install dependencies
run: just install

- name: Install cargo-nextest
uses: taiki-e/install-action@cargo-nextest

- name: Test
shell: bash
run: |
just registry-mock launch
# removing env vars is a temporary workaround for unit tests in pacquet relying on external environment
# this should be removed in the future
unset PNPM_HOME
unset XDG_DATA_HOME
cargo nextest run
just test
just registry-mock end
typos:
name: Spell Check
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,35 @@ jobs:
run_install: false
standalone: true

- name: Cache pnpm
uses: actions/cache@v3
with:
key: codecov-pnpm-${{ matrix.os }}
path: |
${{ env.PNPM_HOME }}/store/v3
${{ env.HOME }}/.local/share/pnpm/store/v3
timeout-minutes: 1
continue-on-error: true

- name: Install just
uses: taiki-e/install-action@just

- name: Install dependencies
run: just install

- name: Run
run: |
just registry-mock launch
# removing env vars is a temporary workaround for unit tests in pacquet relying on external environment
# this should be removed in the future
unset PNPM_HOME
unset XDG_DATA_HOME
cargo codecov --lcov --output-path lcov.info
just registry-mock end
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
Expand Down
61 changes: 61 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ pacquet-executor = { path = "crates/executor" }
pacquet-diagnostics = { path = "crates/diagnostics" }
pacquet-store-dir = { path = "crates/store-dir" }

# Tasks
pacquet-registry-mock = { path = "tasks/registry-mock" }

# Dependencies
advisory-lock = { version = "0.3.0" }
async-recursion = { version = "1.0.5" }
clap = { version = "4", features = ["derive", "string"] }
command-extra = { version = "1.0.0" }
Expand All @@ -45,6 +49,7 @@ junction = { version = "1.0.0" }
reqwest = { version = "0.11", default-features = false, features = ["json", "native-tls-vendored"] }
node-semver = { version = "2.1.0" }
pipe-trait = { version = "0.4.0" }
portpicker = { version = "0.1.1" }
rayon = { version = "1.8.0" }
serde = { version = "1.0.188", features = ["derive"] }
serde_ini = { version = "0.2.0" }
Expand All @@ -54,6 +59,7 @@ sha2 = { version = "0.10.8" }
split-first-char = { version = "0.0.0" }
ssri = { version = "9.0.0" }
strum = { version = "0.25.0", features = ["derive"] }
sysinfo = { version = "0.29.10" }
tar = { version = "0.4.40" }
text-block-macros = { version = "0.1.1" }
tracing = { version = "0.1.37" }
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ Experimental package manager for node.js written in rust.
TRACE=pacquet_tarball just cli add fastify
```

## Testing

```sh
# Install necessary dependencies
just install

# Start a mocked registry server (optional)
just registry-mock launch

# Run test
just test
```

## Benchmarking

### Install between multiple revisions
Expand Down
27 changes: 1 addition & 26 deletions crates/cli/tests/_utils.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
use assert_cmd::prelude::*;
use command_extra::CommandExtra;
use pacquet_store_dir::{PackageFileInfo, PackageFilesIndex};
use pacquet_testing_utils::bin::CommandTempCwd;
use pipe_trait::Pipe;
use std::{
collections::BTreeMap,
ffi::OsStr,
fs::File,
path::{Path, PathBuf},
};
use tempfile::TempDir;
use std::{collections::BTreeMap, fs::File, path::Path};
use walkdir::{DirEntry, WalkDir};

pub fn exec_pacquet_in_temp_cwd<Args>(create_npmrc: bool, args: Args) -> (TempDir, PathBuf)
where
Args: IntoIterator,
Args::Item: AsRef<OsStr>,
{
let env = CommandTempCwd::init();
let (command, root, workspace) = if create_npmrc {
let env = env.add_default_npmrc();
(env.pacquet, env.root, env.workspace)
} else {
(env.pacquet, env.root, env.workspace)
};
command.with_args(args).assert().success();
(root, workspace)
}

pub fn index_file_contents(
store_dir: &Path,
) -> BTreeMap<String, BTreeMap<String, PackageFileInfo>> {
Expand Down
Loading

0 comments on commit f802fdf

Please sign in to comment.