nix-jekyll-builder/tests.nix

53 lines
1.3 KiB
Nix

{ pkgs, mkJekyllSite }:
let
mkTest = name: content: test:
let
testDir = pkgs.runCommand "test-env-${name}" {} ''
mkdir -p $out
cat > $out/index.html <<EOF
${content}
EOF
cat > $out/_config.yml <<EOF
exclude: []
EOF
'';
site = mkJekyllSite {
pname = "test-${name}";
src = testDir;
gemset = ./test-files/gemset.nix;
gemfile = ./test-files/Gemfile;
lockfile = ./test-files/Gemfile.lock;
};
in
pkgs.runCommand "test-${name}" {} ''
${test site}
touch $out
'';
tests = {
basic = mkTest "basic" "<h1>Test Page</h1>" (site: ''
test -f ${site}/index.html || (echo "Missing index.html" && exit 1)
grep -q "<h1>Test Page</h1>" ${site}/index.html
'');
minification = mkTest "minify" "<div> <h1> Test </h1> </div>" (site: ''
! grep -q " " ${site}/index.html || (echo "Not minified" && exit 1)
'');
};
in
{
checks = tests;
apps.test = {
type = "app";
program = "${pkgs.writeScriptBin "run-tests" ''
#!${pkgs.bash}/bin/bash
set -euo pipefail
${builtins.concatStringsSep "\n"
(map (name: "echo Testing ${name}... && test -e ${tests.${name}}")
(builtins.attrNames tests))}
echo "All tests passed!"
''}/bin/run-tests";
};
}