|
573 | 573 | (let [content (slurp (-> opts :modules :c :output-to))] |
574 | 574 | (testing "requires code.split.c" |
575 | 575 | (is (test/document-write? content 'code.split.c))))))) |
| 576 | + |
| 577 | +(deftest test-cljs-2592 |
| 578 | + (test/delete-node-modules) |
| 579 | + (spit (io/file "package.json") "{}") |
| 580 | + (let [cenv (env/default-compiler-env) |
| 581 | + dir (io/file "src" "test" "cljs_build" "package_json_resolution_test") |
| 582 | + out (io/file (test/tmp-dir) "package_json_resolution_test") |
| 583 | + opts {:main 'package-json-resolution-test.core |
| 584 | + :output-dir (str out) |
| 585 | + :output-to (str (io/file out "main.js")) |
| 586 | + :optimizations :none |
| 587 | + :install-deps true |
| 588 | + :npm-deps {:iterall "1.2.2" |
| 589 | + :graphql "0.13.1"} |
| 590 | + :package-json-resolution :nodejs |
| 591 | + :closure-warnings {:check-types :off |
| 592 | + :non-standard-jsdoc :off}}] |
| 593 | + (test/delete-out-files out) |
| 594 | + (build/build (build/inputs dir) opts cenv) |
| 595 | + (testing "processes the iterall index.js" |
| 596 | + (let [index-js (io/file out "node_modules/iterall/index.js")] |
| 597 | + (is (.exists index-js)) |
| 598 | + (is (contains? (:js-module-index @cenv) "iterall")) |
| 599 | + (is (re-find #"goog\.provide\(\"module\$.*\$node_modules\$iterall\$index\"\)" (slurp index-js))))) |
| 600 | + (testing "processes the graphql index.js" |
| 601 | + (let [index-js (io/file out "node_modules/graphql/index.js") |
| 602 | + execution-index-js (io/file out "node_modules/graphql/execution/index.js") |
| 603 | + ast-from-value-js (io/file out "node_modules/grapqhl/utilities/astFromValue.js")] |
| 604 | + (is (.exists index-js)) |
| 605 | + (is (contains? (:js-module-index @cenv) "graphql")) |
| 606 | + (is (re-find #"goog\.provide\(\"module\$.*\$node_modules\$graphql\$index\"\)" (slurp index-js))))) |
| 607 | + (testing "processes a nested index.js in graphql" |
| 608 | + (let [nested-index-js (io/file out "node_modules/graphql/execution/index.js")] |
| 609 | + (is (.exists nested-index-js)) |
| 610 | + (is (contains? (:js-module-index @cenv) "graphql/execution")) |
| 611 | + (is (re-find #"goog\.provide\(\"module\$.*\$node_modules\$graphql\$execution\$index\"\)" (slurp nested-index-js))))) |
| 612 | + (testing "processes cross-package imports" |
| 613 | + (let [ast-from-value-js (io/file out "node_modules/graphql/utilities/astFromValue.js")] |
| 614 | + (is (.exists ast-from-value-js)) |
| 615 | + (is (re-find #"goog.require\(\"module\$.*\$node_modules\$iterall\$index\"\);" (slurp ast-from-value-js))))) |
| 616 | + (testing "adds dependencies to cljs_deps.js" |
| 617 | + (let [deps-js (io/file out "cljs_deps.js")] |
| 618 | + (is (re-find #"goog\.addDependency\(\"..\/node_modules\/iterall\/index.js\"" (slurp deps-js))) |
| 619 | + (is (re-find #"goog\.addDependency\(\"..\/node_modules\/graphql\/index.js\"" (slurp deps-js))) |
| 620 | + (is (re-find #"goog\.addDependency\(\"..\/node_modules\/graphql\/execution/index.js\"" (slurp deps-js))))) |
| 621 | + (testing "adds the right module names to the core.cljs build output" |
| 622 | + (let [core-js (io/file out "package_json_resolution_test/core.js")] |
| 623 | + (is (re-find #"goog\.require\('module\$.*\$node_modules\$iterall\$index'\);" (slurp core-js))) |
| 624 | + (is (re-find #"module\$.+\$node_modules\$iterall\$index\[\"default\"\]\.isCollection" (slurp core-js))) |
| 625 | + (is (re-find #"goog\.require\('module\$.*\$node_modules\$graphql\$index'\);" (slurp core-js))) |
| 626 | + (is (re-find #"module\$.+\$node_modules\$graphql\$index\[\"default\"\]" (slurp core-js)))))) |
| 627 | + (.delete (io/file "package.json")) |
| 628 | + (test/delete-node-modules)) |
0 commit comments