git.iko.soy/typeable/nixpkgs
on master help sign in
cypress.tests.example: init
commit5bf31fbb6dad8c474e5711b21c834a0c1b95cd42 authorRobert Hensing <robert@roberthensing.nl> dateWed 30 Jun 2021, 19:54 (5 years ago) parent6050b70
6 files changed+143−3
pkgs/development/web/cypress/cypress-example-kitchensink/README.md+24 pkgs/development/web/cypress/cypress-example-kitchensink/default.nix+59 pkgs/development/web/cypress/cypress-example-kitchensink/regen-nix+21 pkgs/development/web/cypress/cypress-example-kitchensink/regen-nix.nix+8 pkgs/development/web/cypress/cypress-example-kitchensink/src.nix+6 pkgs/development/web/cypress/default.nix+25−3
pkgs/development/web/cypress/cypress-example-kitchensink/README.mdnew file+24
@@ -0,0 +1,24 @@
1+
2+# `cypress-example-kitchensink`
3+
4+This directory 'packages' [cypress-example-kitchensink](https://github.com/cypress-io/cypress-example-kitchensink),
5+which is used in `cypress.passthru.tests`.
6+
7+The app is not really intended for deployment, so I didn't bother with actual packaging, just testing.
8+If your real-world app looks like `cypress-example-kitchensink`, you'll want to use Nix multiple outputs so you don't deploy your test videos along with your app.
9+Alternatively, you can set it up so that one derivation builds your server exe and another derivation takes that server exe and runs it with the cypress e2e tests.
10+
11+## Peculiarities
12+
13+**cypress and Cypress** are distinct names.
14+ - `cypress` is the npm module, containing the executable `cypress`
15+ - whereas the executable `Cypress` comes from `pkgs.cypress`, a binary distribution (as of writing) by cypress.io.
16+
17+**updateScript** is not provided for this example project. This seems preferable,
18+ because updates to it aren't particularly valuable and have a significant overhead.
19+ The goal is to smoke test `cypress`; not run the latest test suite (which it isn't anyway).
20+
21+## Updating
22+
23+ - update the hash in `src.nix`
24+ - run `regen-nix`
pkgs/development/web/cypress/cypress-example-kitchensink/default.nixnew file+59
@@ -0,0 +1,59 @@
1+{ callPackage
2+, cypress
3+, nodejs-12_x
4+, # FIXME: duplicated from ./regen-nix. node2nix should expose this
5+ nodePackages
6+, xorg
7+, pkgs
8+, stdenv
9+,
10+}:
11+
12+let
13+ fromNode2nix = import ./cypress-example-kitchensink.nix {
14+ inherit pkgs;
15+ };
16+
17+ nodeDependencies = fromNode2nix.shell.nodeDependencies.overrideAttrs (o: {
18+ CYPRESS_INSTALL_BINARY = "0";
19+ PUPPETEER_SKIP_DOWNLOAD = "1";
20+ });
21+
22+ fontConfigEtc = (
23+ pkgs.nixos { config.fonts.fontconfig.enable = true; }
24+ ).config.environment.etc.fonts.source;
25+
26+in
27+stdenv.mkDerivation {
28+ name = "cypress-example-kitchensink";
29+ src = callPackage ./src.nix { };
30+ passthru.fc = fontConfigEtc;
31+ nativeBuildInputs = [
32+ cypress
33+ nodejs-12_x
34+ xorg.xorgserver
35+ nodePackages.jsonplaceholder
36+ ];
37+ FONTCONFIG_PATH = fontConfigEtc;
38+ postPatch = ''
39+ # Use our own offline backend. 15011 means js0n ;)
40+ sed -e 's^https://jsonplaceholder.cypress.io^http://localhost:15011^g' -i $(find . -type f)
41+ '';
42+ buildPhase = ''
43+ ln -s ${nodeDependencies}/lib/node_modules ./node_modules
44+ PATH="${nodeDependencies}/bin:$PATH"
45+ runHook preBuild
46+ PORT=15011 jsonplaceholder &
47+ # assumption: jsonplaceholder start far quicker than cypress run
48+
49+ export CYPRESS_RUN_BINARY=${cypress}/bin/Cypress
50+ export HOME=$PWD/home
51+ mkdir $HOME
52+ npm run test
53+ runHook postBuild
54+ '';
55+ installPhase = ''
56+ mkdir $out
57+ cp -r cypress/videos $out/
58+ '';
59+}
pkgs/development/web/cypress/cypress-example-kitchensink/regen-nixnew file+21
@@ -0,0 +1,21 @@
1+#!/usr/bin/env nix-shell
2+#!nix-shell ./regen-nix.nix
3+#!nix-shell -i bash
4+
5+node2nix \
6+ --nodejs-12 \
7+ --input $src/package.json \
8+ --lock $src/package-lock.json \
9+ --composition cypress-example-kitchensink.nix \
10+ --development \
11+ ;
12+
13+# node2nix produces opinionated expressions that work for in-repo packaging
14+# but aren't ideal for Nixpkgs:
15+sed -i cypress-example-kitchensink.nix \
16+ -e 's^fetchgit^fetchgit callPackage^'
17+sed -i node-packages.nix \
18+ -e 's^fetchgit, ^fetchgit, callPackage, ^' \
19+ -e 's^src = .*/nix/store/.*-source^src = callPackage ./src.nix {}^' \
20+ -e 's^nix-gitignore.gitignoreSourcePure^(ignore: src: src)^' \
21+ ;
pkgs/development/web/cypress/cypress-example-kitchensink/regen-nix.nixnew file+8
@@ -0,0 +1,8 @@
1+{ pkgs ? import ../../../../.. { config = { }; overlays = [ ]; } }:
2+
3+pkgs.mkShell {
4+ nativeBuildInputs = [
5+ pkgs.nodePackages.node2nix
6+ ];
7+ src = pkgs.callPackage ./src.nix { };
8+}
pkgs/development/web/cypress/cypress-example-kitchensink/src.nixnew file+6
@@ -0,0 +1,6 @@
1+{ fetchFromGitHub }: fetchFromGitHub {
2+ owner = "cypress-io";
3+ repo = "cypress-example-kitchensink";
4+ rev = "1572887a2003c2f35ff46d14f5f1cdfef975c9be";
5+ sha256 = "sha256-A7d95b9V707iOzlIg+3nItPPB8HNVVOjPhGqa8MXRPE=";
6+}
pkgs/development/web/cypress/default.nix+25−3
@@ -1,4 +1,20 @@
1−{ stdenv, lib, fetchzip, autoPatchelfHook, xorg, gtk2, gnome2, gtk3, nss, alsa-lib, udev, unzip, wrapGAppsHook, mesa }:
1+{
2+ alsa-lib,
3+ autoPatchelfHook,
4+ callPackage,
5+ fetchzip,
6+ gnome2,
7+ gtk2,
8+ gtk3,
9+ lib,
10+ mesa,
11+ nss,
12+ stdenv,
13+ udev,
14+ unzip,
15+ wrapGAppsHook,
16+ xorg,
17+}:
218
319stdenv.mkDerivation rec {
420 pname = "cypress";
@@ -9,8 +25,6 @@ stdenv.mkDerivation rec {
925 sha256 = "1mr46raha5aqi8ba0cqvyil5z4vcr46hnxqqmpk3fkrr8awd2897";
1026 };
1127
12− passthru.updateScript = ./update.sh;
13−
1428 # don't remove runtime deps
1529 dontPatchELF = true;
1630
@@ -41,6 +55,14 @@ stdenv.mkDerivation rec {
4155 runHook postInstall
4256 '';
4357
58+ passthru = {
59+ updateScript = ./update.sh;
60+
61+ tests = {
62+ example = callPackage ./cypress-example-kitchensink {};
63+ };
64+ };
65+
4466 meta = with lib; {
4567 description = "Fast, easy and reliable testing for anything that runs in a browser";
4668 homepage = "https://www.cypress.io";