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

Factor out npm install step of create-daml-app tests #11294

Merged
merged 3 commits into from
Oct 20, 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
43 changes: 39 additions & 4 deletions daml-assistant/integration-tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,55 @@ da_haskell_test(
],
)

genrule(
name = "create_daml_app_deps",
srcs = [
"//templates:create-daml-app/ui/package.json.template",
"//templates:create-daml-app-test-resources/testDeps.json",
],
outs = ["create_daml_app_deps.tar"],
cmd = """
set -eou pipefail
export PATH=$$PWD/$$(dirname $(location @nodejs//:node_bin)):$$PATH
DIR=$$(mktemp -d)
trap "rm -rf $$DIR" EXIT
mkdir -p $$DIR/cache
mkdir -p $$DIR/deps
# Generate a package.json based on the template with SDK deps dropped
# and merge in the test dependencies.
$(location @jq_dev_env//:bin/jq) -s \
'(.[0] | .name |= "create-daml-app" | .dependencies |= del(."@daml/ledger", ."@daml/react", ."@daml/types", ."@daml.js/__PROJECT_NAME__")) * .[1]' \
$(location //templates:create-daml-app/ui/package.json.template) \
$(location //templates:create-daml-app-test-resources/testDeps.json) > $$DIR/deps/package.json
NPM=$$PWD/$(location @nodejs//:npm_bin)
export NPM_CONFIG_CACHE=$$DIR/cache
(cd $$DIR/deps; $$NPM install --silent --no-update-notifier)
rm -rf $$DIR/deps/package.json
tar cf $(location create_daml_app_deps.tar) -C $$DIR deps
""",
tools = [
"@jq_dev_env//:bin/jq",
"@nodejs//:node_bin",
"@nodejs//:npm_bin",
],
) if not is_windows else None

da_haskell_library(
name = "create-daml-app-tests-lib",
srcs = ["src/DA/Daml/Assistant/CreateDamlAppTests.hs"],
data = [
"//release:sdk-release-tarball",
"@local_jdk//:bin/java.exe" if is_windows else "@local_jdk//:bin/java",
"@local_jdk//:bin/java",
"//:yarn",
"@patch_dev_env//:patch",
] + ([] if is_windows else ts_libraries + create_daml_app_resources),
":create_daml_app_deps.tar",
] + ts_libraries + create_daml_app_resources,
hackage_deps = [
"aeson",
"aeson-extra",
"base",
"bytestring",
"conduit",
"directory",
"extra",
"filepath",
Expand All @@ -198,7 +233,7 @@ da_haskell_library(
"//libs-haskell/da-hs-base",
"//libs-haskell/test-utils",
],
)
) if not is_windows else None

da_haskell_test(
name = "create-daml-app-tests-proj-name",
Expand All @@ -219,4 +254,4 @@ da_haskell_test(
# Exclusive until we stop hardcoding port numbers in index.test.ts
tags = ["exclusive"],
deps = [":create-daml-app-tests-lib"],
)
) if not is_windows else None
Copy link

Choose a reason for hiding this comment

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

So we stop testing this on windows, are has it never been tested there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look at the corresponding test in CreateDamlTest.hs. Before we build the binary and ran the test but the test was a noop. That just seems silly. This PR disables it at the bazel level instead of within the test.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
-- SPDX-License-Identifier: Apache-2.0
module DA.Daml.Assistant.CreateDamlAppTests (main) where

import Conduit
import Control.Exception.Extra
import Control.Monad
import Data.Aeson
import Data.Aeson.Extra.Merge
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString as BS
import qualified Data.Conduit.Tar.Extra as Tar.Conduit.Extra
import qualified Data.HashMap.Strict as HMS
import Data.List.Extra
import Data.Proxy (Proxy (..))
Expand Down Expand Up @@ -57,7 +59,7 @@ tests :: TestTree
tests =
withSdkResource $ \_ ->
askOption $ \(ProjectName projectName) -> do
testGroup "Create DAML App tests" [gettingStartedGuideTest projectName | not isWindows]
testGroup "Create DAML App tests" [gettingStartedGuideTest projectName]
where
gettingStartedGuideTest projectName = testCaseSteps "Getting Started Guide" $ \step ->
withTempDir $ \tmpDir' -> do
Expand Down Expand Up @@ -87,6 +89,11 @@ tests =
extraDepsFile <- locateRunfiles (mainWorkspace </> "templates" </> "create-daml-app-test-resources" </> "testDeps.json")
addTestDependencies (uiDir </> "package.json") extraDepsFile
step "Install dependencies for UI"
createDirectoryIfMissing True "node_modules"
cachedDeps <- locateRunfiles (mainWorkspace </> "daml-assistant" </> "integration-tests" </> "create_daml_app_deps.tar")
runConduitRes
$ sourceFileBS cachedDeps
.| Tar.Conduit.Extra.untar (Tar.Conduit.Extra.restoreFile (\a b -> fail (T.unpack $ a <> " " <> b)) ".")
retry 3 (callCommandSilent "npm-cli.js install")
step "Run linter"
callCommandSilent "npm-cli.js run-script lint -- --max-warnings 0"
Expand Down
5 changes: 4 additions & 1 deletion templates/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
# SPDX-License-Identifier: Apache-2.0
load("@os_info//:os_info.bzl", "is_windows")

exports_files(glob(["create-daml-app-test-resources/*"]) + ["copy-trigger/src/CopyTrigger.daml"])
exports_files(glob(["create-daml-app-test-resources/*"]) + [
"copy-trigger/src/CopyTrigger.daml",
"create-daml-app/ui/package.json.template",
])

# Split out into a separate rule so we can cheaply include this in the
# live-preview.
Expand Down