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

nodePackages.postcss-cli: add passthru.tests #130204

Merged
merged 1 commit into from
Jul 18, 2021
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
5 changes: 5 additions & 0 deletions pkgs/development/node-packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ let
--prefix NODE_PATH : ${self.postcss}/lib/node_modules \
--prefix NODE_PATH : ${self.autoprefixer}/lib/node_modules
'';
passthru.tests = {
simple-execution = pkgs.callPackage ./package-tests/postcss-cli.nix {
inherit (self) postcss-cli;
};
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also relevant for the autoprefixer package. You could add it there as well.

meta.mainProgram = "postcss";
};

Expand Down
45 changes: 45 additions & 0 deletions pkgs/development/node-packages/package-tests/postcss-cli.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{ runCommand, postcss-cli }:

let
inherit (postcss-cli) packageName version;
in

runCommand "${packageName}-tests" { meta.timeout = 60; }
''
# get version of installed program and compare with package version
claimed_version="$(${postcss-cli}/bin/postcss --version)"
if [[ "$claimed_version" != "${version}" ]]; then
echo "Error: program version does not match package version ($claimed_version != ${version})"
exit 1
fi

# run basic help command
${postcss-cli}/bin/postcss --help > /dev/null

roberth marked this conversation as resolved.
Show resolved Hide resolved
# basic autoprefixer test
config_dir="$(mktemp -d)"
clean_up() {
rm -rf "$config_dir"
}
trap clean_up EXIT
echo "
module.exports = {
plugins: {
'autoprefixer': { overrideBrowserslist: 'chrome 40' },
},
}
" > "$config_dir/postcss.config.js"
input='a{ user-select: none; }'
expected_output='a{ -webkit-user-select: none; user-select: none; }'
actual_output="$(echo $input | ${postcss-cli}/bin/postcss --no-map --config $config_dir)"
if [[ "$actual_output" != "$expected_output" ]]; then
echo "Error: autoprefixer did not output the correct CSS:"
echo "$actual_output"
echo "!="
echo "$expected_output"
exit 1
fi

# needed for Nix to register the command as successful
touch $out
''