diff --git a/daml-assistant/integration-tests/BUILD.bazel b/daml-assistant/integration-tests/BUILD.bazel index 34f90da34dc7..6bf52ee52236 100644 --- a/daml-assistant/integration-tests/BUILD.bazel +++ b/daml-assistant/integration-tests/BUILD.bazel @@ -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", @@ -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", @@ -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 diff --git a/daml-assistant/integration-tests/src/DA/Daml/Assistant/CreateDamlAppTests.hs b/daml-assistant/integration-tests/src/DA/Daml/Assistant/CreateDamlAppTests.hs index ba9014f6c560..de709208929e 100644 --- a/daml-assistant/integration-tests/src/DA/Daml/Assistant/CreateDamlAppTests.hs +++ b/daml-assistant/integration-tests/src/DA/Daml/Assistant/CreateDamlAppTests.hs @@ -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 (..)) @@ -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 @@ -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" diff --git a/templates/BUILD.bazel b/templates/BUILD.bazel index 8736160467ed..0bca28d13c52 100644 --- a/templates/BUILD.bazel +++ b/templates/BUILD.bazel @@ -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.