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

rearrange tests #7

Merged
merged 3 commits into from
Aug 11, 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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ watch: ## Watch for the filesystem and rebuild on every change

.PHONY: test
test: ## Run tests
$(DUNE) build @runtest
# Needed to avoid errors with lock "Another process has locked /home/me/.opam/config.lock, waiting (C-c to abort)..."
$(DUNE) build @runtest -j 1
1 change: 0 additions & 1 deletion opam-check-npm-deps.opam
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ build: [
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
Expand Down
2 changes: 1 addition & 1 deletion src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ let check_npm_deps cli =
Unknown package flags deprecated ignored *)
OpamCoreConfig.update ~verbose_level:0 ();
OpamGlobalState.with_ `Lock_none @@ fun gt ->
OpamSwitchState.with_ `Lock_write gt @@ fun st ->
OpamSwitchState.with_ `Lock_none gt @@ fun st ->
let npm_depexts =
List.filter_map
(fun pkg ->
Expand Down
39 changes: 39 additions & 0 deletions test/dry-run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
When --dry-run is used, exit code is 0

$ OPAMNOENVNOTICE="true" opam switch create . --empty

$ cat > test.opam <<EOF
> opam-version: "2.0"
> name: "test"
> synopsis: "One-line description"
> description: """
> Longer description
> """
> maintainer: "Name <email>"
> authors: "Name <email>"
> homepage: "https://github.com/test/project"
> bug-reports: "https://github.com/test/project/issues"
> depexts: [
> ["react"] {npm-version = "^16.0.2"}
> ]
> EOF

$ opam pin add -y test.dev . | grep "installed"
-> installed test.dev

$ cat > package.json <<EOF
> {
> "license": "MIT",
> "dependencies": {
> "react": "^18.2.0"
> }
> }
> EOF

$ yarn install --silent

$ opam-check-npm-deps --dry-run
Error: opam package "test.dev" requires npm package "react" with constraint "^16.0.2", but the version installed found in file "$TESTCASE_ROOT/node_modules/react/package.json" is "18.2.0"

$ opam switch remove -y .
Switch $TESTCASE_ROOT and all its packages will be wiped. Are you sure? [Y/n] y
33 changes: 33 additions & 0 deletions test/error-no-node_module.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Errors when node_module folder is not found

$ OPAMNOENVNOTICE="true" opam switch create . --empty

$ cat > test.opam <<EOF
> opam-version: "2.0"
> name: "test"
> synopsis: "One-line description"
> description: """
> Longer description
> """
> maintainer: "Name <email>"
> authors: "Name <email>"
> homepage: "https://github.com/test/project"
> bug-reports: "https://github.com/test/project/issues"
> depexts: [
> ["react"] {npm-version = "^16.0.2"}
> ["react-dom"] {npm-version = "^16.0.2"}
> ]
> EOF

$ opam pin add -y test.dev . | grep "installed"
-> installed test.dev

$ rm -rf node_modules

$ opam-check-npm-deps
Error: opam package "test.dev" requires npm package "react-dom" with constraint "^16.0.2", but file "$TESTCASE_ROOT/node_modules/react-dom/package.json" can not be found
Error: opam package "test.dev" requires npm package "react" with constraint "^16.0.2", but file "$TESTCASE_ROOT/node_modules/react/package.json" can not be found
[1]

$ opam switch remove -y .
Switch $TESTCASE_ROOT and all its packages will be wiped. Are you sure? [Y/n] y
29 changes: 29 additions & 0 deletions test/error-non-eq-filter.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Errors when using npm-version without an equality filter `=`

$ OPAMNOENVNOTICE="true" opam switch create . --empty

$ cat > test.opam <<EOF
> opam-version: "2.0"
> name: "test"
> synopsis: "One-line description"
> description: """
> Longer description
> """
> maintainer: "Name <email>"
> authors: "Name <email>"
> homepage: "https://github.com/test/project"
> bug-reports: "https://github.com/test/project/issues"
> depexts: [
> ["react"] {npm-version >= "^16.0.2"}
> ]
> EOF

$ opam pin add -y test.dev . | grep "installed"
-> installed test.dev

$ opam-check-npm-deps
Warning: package test.dev includes an invalid npm-version constraint which does not use equality in its formula: npm-version >= "^16.0.2".
To fix the issue, use an equality formula, e.g. {npm-version = "^1.0.0"}

$ opam switch remove -y .
Switch $TESTCASE_ROOT and all its packages will be wiped. Are you sure? [Y/n] y
43 changes: 43 additions & 0 deletions test/error-version-not-match.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Errors when version does not match

$ OPAMNOENVNOTICE="true" opam switch create . --empty

$ cat > test.opam <<EOF
> opam-version: "2.0"
> name: "test"
> synopsis: "One-line description"
> description: """
> Longer description
> """
> maintainer: "Name <email>"
> authors: "Name <email>"
> homepage: "https://github.com/test/project"
> bug-reports: "https://github.com/test/project/issues"
> depexts: [
> ["react"] {npm-version = "^16.0.2"}
> ["react-dom"] {npm-version = "^16.0.2"}
> ]
> EOF

$ opam pin add -y test.dev . | grep "installed"
-> installed test.dev

$ cat > package.json <<EOF
> {
> "license": "MIT",
> "dependencies": {
> "react": "^18.2.0",
> "react-dom": "^18.2.0"
> }
> }
> EOF

$ yarn install --silent

$ opam-check-npm-deps
Error: opam package "test.dev" requires npm package "react-dom" with constraint "^16.0.2", but the version installed found in file "$TESTCASE_ROOT/node_modules/react-dom/package.json" is "18.2.0"
Error: opam package "test.dev" requires npm package "react" with constraint "^16.0.2", but the version installed found in file "$TESTCASE_ROOT/node_modules/react/package.json" is "18.2.0"
[1]

$ opam switch remove -y .
Switch $TESTCASE_ROOT and all its packages will be wiped. Are you sure? [Y/n] y
220 changes: 0 additions & 220 deletions test/main.t

This file was deleted.

Loading