git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #130204 from Luflosi/postcss-cli-add-tests

nodePackages.postcss-cli: add passthru.tests

commit03a17d756a6c9097f04c082fe7ce05d6079fbc89 authorRobert Hensing <roberth@users.noreply.github.com> dateSun 18 Jul 2021, 19:07 (5 years ago) parentb2fac1c703b9b1
2 files changed+50
pkgs/development/node-packages/default.nix+5 pkgs/development/node-packages/package-tests/postcss-cli.nix+45
pkgs/development/node-packages/default.nix+5
@@ -276,6 +276,11 @@ let
276276 --prefix NODE_PATH : ${self.postcss}/lib/node_modules \
277277 --prefix NODE_PATH : ${self.autoprefixer}/lib/node_modules
278278 '';
279+ passthru.tests = {
280+ simple-execution = pkgs.callPackage ./package-tests/postcss-cli.nix {
281+ inherit (self) postcss-cli;
282+ };
283+ };
279284 meta.mainProgram = "postcss";
280285 };
281286
pkgs/development/node-packages/package-tests/postcss-cli.nixnew file+45
@@ -0,0 +1,45 @@
1+{ runCommand, postcss-cli }:
2+
3+let
4+ inherit (postcss-cli) packageName version;
5+in
6+
7+runCommand "${packageName}-tests" { meta.timeout = 60; }
8+ ''
9+ # get version of installed program and compare with package version
10+ claimed_version="$(${postcss-cli}/bin/postcss --version)"
11+ if [[ "$claimed_version" != "${version}" ]]; then
12+ echo "Error: program version does not match package version ($claimed_version != ${version})"
13+ exit 1
14+ fi
15+
16+ # run basic help command
17+ ${postcss-cli}/bin/postcss --help > /dev/null
18+
19+ # basic autoprefixer test
20+ config_dir="$(mktemp -d)"
21+ clean_up() {
22+ rm -rf "$config_dir"
23+ }
24+ trap clean_up EXIT
25+ echo "
26+ module.exports = {
27+ plugins: {
28+ 'autoprefixer': { overrideBrowserslist: 'chrome 40' },
29+ },
30+ }
31+ " > "$config_dir/postcss.config.js"
32+ input='a{ user-select: none; }'
33+ expected_output='a{ -webkit-user-select: none; user-select: none; }'
34+ actual_output="$(echo $input | ${postcss-cli}/bin/postcss --no-map --config $config_dir)"
35+ if [[ "$actual_output" != "$expected_output" ]]; then
36+ echo "Error: autoprefixer did not output the correct CSS:"
37+ echo "$actual_output"
38+ echo "!="
39+ echo "$expected_output"
40+ exit 1
41+ fi
42+
43+ # needed for Nix to register the command as successful
44+ touch $out
45+ ''