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

test: add integration tests #248

Merged
merged 6 commits into from
Aug 18, 2022
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
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ jobs:

- run: nix flake check

tests-integration:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- 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 }}
- uses: cachix/cachix-action@v10
with:
name: nix-community
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'

- run: nix run .#tests-integration

tests-unit-nix:
runs-on: ubuntu-latest
Expand Down
10 changes: 10 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand Down
51 changes: 51 additions & 0 deletions tests/integration/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
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 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"
''
1 change: 1 addition & 0 deletions tests/integration/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flake.lock
27 changes: 27 additions & 0 deletions tests/integration/tests/nodejs_built-binary/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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";
};

outputs = {
self,
dream2nix,
}: (dream2nix.lib.makeFlakeOutputs {
systems = ["x86_64-linux"];
config.projectRoot = ./.;
source = ./.;
});
}
10 changes: 10 additions & 0 deletions tests/integration/tests/nodejs_built-binary/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "test-built-binary",
"version": "1.0.0",
"bin": {
"main": "./main.js"
},
"scripts": {
"build": "touch main.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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";
};

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
'';
};
};
};
});
}
Original file line number Diff line number Diff line change
@@ -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"
}
}