Skip to content

Commit

Permalink
test: add workspace tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nokazn committed Feb 11, 2024
1 parent 053057b commit 027b3f7
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
result
.direnv
node_modules
50 changes: 46 additions & 4 deletions src/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ use crate::{

#[derive(Debug)]
pub struct Workspaces {
kind: PackageManagerKind,
pub packages: Vec<PathBuf>,
}

impl Workspaces {
pub fn new(base_dir: PathBuf, kind: PackageManagerKind, patterns: Option<Vec<String>>) -> Self {
Self {
kind: kind,
packages: match &kind {
PackageManagerKind::Npm => Workspaces::resolve_npm_workspaces(base_dir, patterns),
PackageManagerKind::Bun => Workspaces::resolve_bun_workspaces(base_dir, patterns),
Expand Down Expand Up @@ -103,7 +101,6 @@ mod tests {
fn test_new_each(case: NewTestCase) {
let base_dir = case.input.0;
let workspaces = Workspaces::new(base_dir.clone(), case.input.1, case.input.2);
assert_eq!(workspaces.kind, case.expected.kind);
assert_eq!(
workspaces.packages,
case
Expand All @@ -117,6 +114,52 @@ mod tests {

test_each_serial!(
test_new,
"npm_evaluate_negate_patterns" => NewTestCase {
input: (
PathBuf::from("tests/fixtures/workspaces/npm"),
PackageManagerKind::Npm,
Some(vec![
String::from("packages/*"),
String::from("!packages/c"),
]),
),
expected: Workspaces {
packages: vec![
PathBuf::from("./packages/a"),
PathBuf::from("./packages/b"),
],
},
},
"yarn_evaluate_negate_patterns" => NewTestCase {
input: (
PathBuf::from("tests/fixtures/workspaces/yarn"),
PackageManagerKind::Yarn,
Some(vec![
String::from("packages/*"),
String::from("!packages/c"),
]),
),
expected: Workspaces {
packages: vec![
PathBuf::from("./packages/a"),
PathBuf::from("./packages/b"),
PathBuf::from("./packages/c"),
],
},
},
"pnpm_evaluate_negate_patterns" => NewTestCase {
input: (
PathBuf::from("tests/fixtures/workspaces/pnpm"),
PackageManagerKind::Pnpm,
None,
),
expected: Workspaces {
packages: vec![
PathBuf::from("./packages/a"),
PathBuf::from("./packages/b"),
],
},
},
"bun" => NewTestCase {
input: (
PathBuf::from("tests/fixtures/workspaces/bun"),
Expand All @@ -127,7 +170,6 @@ mod tests {
]),
),
expected: Workspaces {
kind: PackageManagerKind::Bun,
packages: vec![
PathBuf::from("./packages/a"),
PathBuf::from("./packages/b"),
Expand Down
Empty file.
24 changes: 24 additions & 0 deletions tests/fixtures/workspaces/npm/package-lock.json

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

5 changes: 5 additions & 0 deletions tests/fixtures/workspaces/npm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"typescript": "^5.3.3"
}
}
Empty file.
1 change: 1 addition & 0 deletions tests/fixtures/workspaces/npm/packages/c/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions tests/fixtures/workspaces/pnpm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"typescript": "^5.3.3"
}
}
1 change: 1 addition & 0 deletions tests/fixtures/workspaces/pnpm/packages/a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Empty file.
1 change: 1 addition & 0 deletions tests/fixtures/workspaces/pnpm/packages/c/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
25 changes: 25 additions & 0 deletions tests/fixtures/workspaces/pnpm/pnpm-lock.yaml

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

3 changes: 3 additions & 0 deletions tests/fixtures/workspaces/pnpm/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
- 'packages/*'
- '!packages/c'
5 changes: 5 additions & 0 deletions tests/fixtures/workspaces/yarn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"typescript": "^5.3.3"
}
}
1 change: 1 addition & 0 deletions tests/fixtures/workspaces/yarn/packages/a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Empty file.
1 change: 1 addition & 0 deletions tests/fixtures/workspaces/yarn/packages/c/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
8 changes: 8 additions & 0 deletions tests/fixtures/workspaces/yarn/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


typescript@^5.3.3:
version "5.3.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==

0 comments on commit 027b3f7

Please sign in to comment.