depot/pkgs/development/node-packages/package-tests/postcss-cli.nix
Luke Granger-Brown 57725ef3ec Squashed 'third_party/nixpkgs/' content from commit 76612b17c0ce
git-subtree-dir: third_party/nixpkgs
git-subtree-split: 76612b17c0ce71689921ca12d9ffdc9c23ce40b2
2024-11-10 23:59:47 +00:00

45 lines
1.3 KiB
Nix

{ 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
# 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
''