From 4dca0944aba19349c0ce37a12380bf25a998fc19 Mon Sep 17 00:00:00 2001 From: Martin Toman Date: Thu, 11 Aug 2022 12:27:21 -0700 Subject: [PATCH 1/6] test: add integration test for #235 --- flake.nix | 10 ++++ tests/integration/default.nix | 52 +++++++++++++++++++ tests/integration/tests/.gitignore | 1 + .../tests/nodejs_built-binary/flake.nix | 14 +++++ .../tests/nodejs_built-binary/package.json | 10 ++++ 5 files changed, 87 insertions(+) create mode 100644 tests/integration/default.nix create mode 100644 tests/integration/tests/.gitignore create mode 100644 tests/integration/tests/nodejs_built-binary/flake.nix create mode 100644 tests/integration/tests/nodejs_built-binary/package.json diff --git a/flake.nix b/flake.nix index 21cdde3a5d..a011ca181b 100644 --- a/flake.nix +++ b/flake.nix @@ -174,6 +174,13 @@ inherit self; }); + tests-integration.type = "app"; + tests-integration.program = + b.toString + (dream2nixFor."${system}".callPackageDream ./tests/integration { + inherit self; + }); + tests-examples.type = "app"; tests-examples.program = b.toString @@ -201,6 +208,9 @@ echo "running unit tests" ${self.apps.${system}.tests-unit.program} + echo "running integration tests" + ${self.apps.${system}.tests-integration.program} + echo "checking flakes under ./examples" ${self.apps.${system}.tests-examples.program} diff --git a/tests/integration/default.nix b/tests/integration/default.nix new file mode 100644 index 0000000000..fbbab6cd2d --- /dev/null +++ b/tests/integration/default.nix @@ -0,0 +1,52 @@ +{ + self, + lib, + async, + bash, + coreutils, + git, + parallel, + nix, + utils, + dream2nixWithExternals, + ... +}: let + l = lib // builtins; + tests = ./tests; + testScript = + utils.writePureShellScript + [ + async + bash + coreutils + git + nix + ] + '' + dir=$1 + shift + echo -e "\nrunning test $dir" + cp -r ${tests}/$dir/* . + chmod -R +w . + nix flake lock --override-input dream2nix ${../../.} + nix run .#resolveImpure || echo "no resolveImpure probably?" + nix eval --read-only --no-allow-import-from-derivation .#default.name + nix build + nix flake check "$@" + ''; +in + utils.writePureShellScript + [ + coreutils + parallel + ] + '' + if [ -z ''${1+x} ]; then + parallel --halt now,fail=1 -j$(nproc) -a <(ls ${tests}) ${testScript} + else + arg1=$1 + shift + ${testScript} $arg1 "$@" + fi + echo "done running integration tests" + '' diff --git a/tests/integration/tests/.gitignore b/tests/integration/tests/.gitignore new file mode 100644 index 0000000000..301d47e19e --- /dev/null +++ b/tests/integration/tests/.gitignore @@ -0,0 +1 @@ +flake.lock diff --git a/tests/integration/tests/nodejs_built-binary/flake.nix b/tests/integration/tests/nodejs_built-binary/flake.nix new file mode 100644 index 0000000000..391c2a74ca --- /dev/null +++ b/tests/integration/tests/nodejs_built-binary/flake.nix @@ -0,0 +1,14 @@ +{ + inputs = { + dream2nix.url = "github:nix-community/dream2nix"; + }; + + outputs = { + self, + dream2nix, + }: (dream2nix.lib.makeFlakeOutputs { + systems = ["x86_64-linux"]; + config.projectRoot = ./.; + source = ./.; + }); +} diff --git a/tests/integration/tests/nodejs_built-binary/package.json b/tests/integration/tests/nodejs_built-binary/package.json new file mode 100644 index 0000000000..dcd3860ea4 --- /dev/null +++ b/tests/integration/tests/nodejs_built-binary/package.json @@ -0,0 +1,10 @@ +{ + "name": "test-built-binary", + "version": "1.0.0", + "bin": { + "main": "./main.js" + }, + "scripts": { + "build": "touch main.js" + } +} From 7c4a5a505f8df234f294abdd902315f79582a528 Mon Sep 17 00:00:00 2001 From: Martin Toman Date: Thu, 11 Aug 2022 12:31:57 -0700 Subject: [PATCH 2/6] test: run .#tests-integration in github action --- .github/workflows/tests.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 66e1dcbb7a..eb546fda99 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,6 +39,18 @@ jobs: - run: nix flake check + tests-integration: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.4.0 + - uses: cachix/install-nix-action@v15 + with: + install_url: https://nixos-nix-install-tests.cachix.org/serve/w659aglf1hfvkj5wj696q9x8r19p6b7k/install + install_options: '--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve' + extra_nix_config: | + access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} + + - run: nix run .#tests-integration tests-unit-nix: runs-on: ubuntu-latest From c8faa3e7d27831821c969f95cbcee4f494303f7d Mon Sep 17 00:00:00 2001 From: Martin Toman Date: Thu, 11 Aug 2022 13:02:52 -0700 Subject: [PATCH 3/6] test: add integration test for #221 --- .../flake.nix | 32 +++++++++++++++++++ .../package.json | 11 +++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/integration/tests/nodejs_direct-priority-over-transitive/flake.nix create mode 100644 tests/integration/tests/nodejs_direct-priority-over-transitive/package.json diff --git a/tests/integration/tests/nodejs_direct-priority-over-transitive/flake.nix b/tests/integration/tests/nodejs_direct-priority-over-transitive/flake.nix new file mode 100644 index 0000000000..568ac497c6 --- /dev/null +++ b/tests/integration/tests/nodejs_direct-priority-over-transitive/flake.nix @@ -0,0 +1,32 @@ +{ + inputs = { + dream2nix.url = "github:nix-community/dream2nix"; + }; + + outputs = { + self, + dream2nix, + }: (dream2nix.lib.makeFlakeOutputs { + systems = ["x86_64-linux"]; + config.projectRoot = ./.; + source = ./.; + packageOverrides = { + test = { + "check-linked-bin-version" = { + postInstall = '' + npm run get-version + VERSION=$(cat VERSION) + echo "$VERSION" + + if [ "$VERSION" = "2.8.0" ]; then + echo "correct version installed - direct dependency" + else + echo "wrong version installed - transitive dependency" + exit 1 + fi + ''; + }; + }; + }; + }); +} diff --git a/tests/integration/tests/nodejs_direct-priority-over-transitive/package.json b/tests/integration/tests/nodejs_direct-priority-over-transitive/package.json new file mode 100644 index 0000000000..c06d8fdc2b --- /dev/null +++ b/tests/integration/tests/nodejs_direct-priority-over-transitive/package.json @@ -0,0 +1,11 @@ +{ + "name": "test", + "version": "1.0.0", + "scripts": { + "get-version": "svgo --version > VERSION" + }, + "devDependencies": { + "svgo": "2.8.0", + "cssnano": "4.1.10" + } +} From fd0fa4da8670b9d79912959138fba914e5ea7f62 Mon Sep 17 00:00:00 2001 From: Martin Toman Date: Thu, 11 Aug 2022 14:11:54 -0700 Subject: [PATCH 4/6] Run build & check default for .#tests-integration --- tests/integration/default.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/default.nix b/tests/integration/default.nix index fbbab6cd2d..4c058c8560 100644 --- a/tests/integration/default.nix +++ b/tests/integration/default.nix @@ -30,9 +30,8 @@ chmod -R +w . nix flake lock --override-input dream2nix ${../../.} nix run .#resolveImpure || echo "no resolveImpure probably?" - nix eval --read-only --no-allow-import-from-derivation .#default.name nix build - nix flake check "$@" + nix flake check ''; in utils.writePureShellScript From dd889bc4f7641d3c91dba9989e4f94774e6ad36e Mon Sep 17 00:00:00 2001 From: Martin Toman Date: Wed, 17 Aug 2022 12:44:59 -0700 Subject: [PATCH 5/6] test: add descriptions for integration tests --- .../tests/nodejs_built-binary/flake.nix | 13 +++++++++++++ .../flake.nix | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/integration/tests/nodejs_built-binary/flake.nix b/tests/integration/tests/nodejs_built-binary/flake.nix index 391c2a74ca..351dafc106 100644 --- a/tests/integration/tests/nodejs_built-binary/flake.nix +++ b/tests/integration/tests/nodejs_built-binary/flake.nix @@ -1,3 +1,16 @@ +# test: node.js built binary +# +# Detecting regressions of #235. +# +# Node.js builder was crashing if a binary defined in package.json +# bin section refers to a file that does not exist before the build step. +# +# 1. "package.json".bin.main = "./main.js" +# 2. `main.js` does not exist, but is created during the build +# 3. the default build script "package.json".scripts.build creates `main.js` +# during the buildPhase +# 4. the binary is linked to the bin directory in the installPhase +# { inputs = { dream2nix.url = "github:nix-community/dream2nix"; diff --git a/tests/integration/tests/nodejs_direct-priority-over-transitive/flake.nix b/tests/integration/tests/nodejs_direct-priority-over-transitive/flake.nix index 568ac497c6..17057e7be5 100644 --- a/tests/integration/tests/nodejs_direct-priority-over-transitive/flake.nix +++ b/tests/integration/tests/nodejs_direct-priority-over-transitive/flake.nix @@ -1,3 +1,17 @@ +# test: node.js direct dep priority over transitive dep +# +# Detecting regressions for #221. +# +# Node.js builder was linking the wrong version of a binary, +# if there was another dependency transitivelly depending on another version, +# this one would be resolved instead of the direct dependency. +# +# Dependencies: svgo@2, cssnano@4 (cssnano@4 -> svgo@1) +# +# 1. Dream2Nix normal build. +# 2. Get version of svgo in node.js path. (npm run get-version = svgo --version) +# 3. Check if this is the same version as the direct dependency. +# { inputs = { dream2nix.url = "github:nix-community/dream2nix"; From 3aa9927b0de69d95b6b74ffaf8e34491e8ff3e2c Mon Sep 17 00:00:00 2001 From: Martin Toman Date: Wed, 17 Aug 2022 13:30:04 -0700 Subject: [PATCH 6/6] ci: enable cachix for integration-tests --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index eb546fda99..ba30f91cd9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -49,6 +49,10 @@ jobs: install_options: '--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve' extra_nix_config: | access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} + - uses: cachix/cachix-action@v10 + with: + name: nix-community + signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}' - run: nix run .#tests-integration