ts_test.conf 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. TS_TEST_EXTENSION=
  2. TS_TEST_EXTRA_SRCS_MASK=
  3. TS_TEST_CONFIG_PATH=
  4. TS_TEST_NM=
  5. _TS_TEST_DEPENDS_ON_BUILD=
  6. # We have to rename node_modules.tar to workspace_node_modules.tar,
  7. # so TS_TEST_JEST module has it's own unique output.
  8. # TS_TEST_JEST_FOR module has to output all files required for test run.
  9. TS_TEST_JEST_CMD=$TOUCH_UNIT \
  10. && $NOTS_TOOL $NOTS_TOOL_BASE_ARGS create-node-modules --moddir $TS_TEST_FOR_PATH \
  11. $_NODE_MODULES_INOUTS ${hide:PEERS} \
  12. && ${cwd:BINDIR} $MOVE_FILE $TS_TEST_NM ${output:"workspace_node_modules.tar"} \
  13. ${kv;hide:"p TS_JST"} ${kv;hide:"pc magenta"}
  14. ### @usage: TS_TEST_JEST_FOR(Path)
  15. ###
  16. ### Defines testing module with jest test runner.
  17. ###
  18. ### @example
  19. ###
  20. ### TS_TEST_JEST_FOR(path/to/module)
  21. ### TS_TEST_SRCS(../src)
  22. ### TS_TEST_CONFIG(../jest.config.js)
  23. ### END()
  24. ###
  25. module TS_TEST_JEST_FOR: _TS_TEST_BASE {
  26. .CMD=TS_TEST_JEST_CMD
  27. # for multimodule peers we should choose NODE_MODULES
  28. SET(PEERDIR_TAGS NODE_MODULES)
  29. # compatibility with old TS_TEST_SRCS
  30. SET(TS_TEST_EXTENSION test.(ts|tsx|js|jsx))
  31. SET(TS_TEST_EXTRA_SRCS_MASK /**/__mocks__/*)
  32. # nots.py will decide if we need to depend on the testing target module output
  33. _DEPENDS_ON_MOD()
  34. _PEERDIR_TS_RESOURCE(nodejs pnpm jest)
  35. _TS_TEST_FOR_CONFIGURE(jest jest.config.js workspace_node_modules.tar)
  36. _TS_ADD_NODE_MODULES_FOR_BUILDER()
  37. }
  38. TS_TEST_HERMIONE_CMD=$TOUCH_UNIT \
  39. && ${cwd:BINDIR} $MOVE_FILE ${input:TS_TEST_NM} ${output:"workspace_node_modules.tar"} \
  40. ${kv;hide:"p TSHRM"} ${kv;hide:"pc magenta"}
  41. ### @usage: TS_TEST_HERMIONE_FOR(Path)
  42. ###
  43. ### Defines testing module with hermione test runner.
  44. ###
  45. ### @example
  46. ###
  47. ### TS_TEST_HERMIONE_FOR(path/to/module)
  48. ### TS_TEST_SRCS(../src)
  49. ### TS_TEST_CONFIG(../hermione.conf.js)
  50. ### END()
  51. ###
  52. module TS_TEST_HERMIONE_FOR: _TS_TEST_BASE {
  53. .CMD=TS_TEST_HERMIONE_CMD
  54. # for multimodule peers we should choose TS
  55. SET(PEERDIR_TAGS TS)
  56. # compatibility with old TS_TEST_SRCS
  57. SET(TS_TEST_EXTENSION hermione.(ts|js))
  58. TS_TEST_DEPENDS_ON_BUILD()
  59. _DEPENDS_ON_MOD()
  60. _PEERDIR_TS_RESOURCE(nodejs pnpm typescript hermione)
  61. _TS_TEST_FOR_CONFIGURE(hermione .hermione.conf.js workspace_node_modules.tar)
  62. }
  63. TS_TEST_PLAYWRIGHT_CMD=$TOUCH_UNIT \
  64. && $NOTS_TOOL $NOTS_TOOL_BASE_ARGS create-node-modules --moddir $TS_TEST_FOR_PATH \
  65. $_NODE_MODULES_INOUTS ${hide:PEERS} \
  66. && ${cwd:BINDIR} $MOVE_FILE $TS_TEST_NM ${output:"workspace_node_modules.tar"} \
  67. ${kv;hide:"p TSPW"} ${kv;hide:"pc magenta"}
  68. ### @usage: TS_TEST_PLAYWRIGHT_FOR(Path)
  69. ###
  70. ### Defines testing module with playwright test runner.
  71. ###
  72. ### @example
  73. ###
  74. ### TS_TEST_PLAYWRIGHT_FOR(path/to/module)
  75. ### TS_TEST_SRCS(../src)
  76. ### TS_TEST_CONFIG(../playwright.config.js)
  77. ### END()
  78. ###
  79. module TS_TEST_PLAYWRIGHT_FOR: _TS_TEST_BASE {
  80. .CMD=TS_TEST_PLAYWRIGHT_CMD
  81. # for multimodule peers we should choose TS
  82. SET(PEERDIR_TAGS TS)
  83. # compatibility with old TS_TEST_SRCS
  84. SET(TS_TEST_EXTENSION (playwright|spec).(ts|js))
  85. _DEPENDS_ON_MOD()
  86. _TS_ADD_NODE_MODULES_FOR_BUILDER()
  87. _PEERDIR_TS_RESOURCE(nodejs pnpm playwright)
  88. _TS_TEST_FOR_CONFIGURE(playwright playwright.config.ts workspace_node_modules.tar)
  89. }
  90. module _TS_TEST_BASE: _BARE_UNIT {
  91. # ignore SRCS macro
  92. .ALIASES=SRCS=_NOOP_MACRO
  93. # use this parser to get module args in $MODULE_ARGS_RAW
  94. .ARGS_PARSER=Raw
  95. .NODE_TYPE=Program
  96. # .fake tells builder to not materialize it in results
  97. SET(MODULE_SUFFIX .ts_test.fake)
  98. # include processor works only for TS tag
  99. SET(MODULE_TAG TS)
  100. SET(MODULE_LANG TS)
  101. # we read erm-packages.json during configuration, so we have to include it to configuration cache key
  102. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${ARCADIA_ROOT}/$ERM_PACKAGES_PATH)
  103. # parse module args
  104. _TS_TEST_FOR_ARGS($MODULE_ARGS_RAW)
  105. # we don't want to have TS outputs for tests
  106. DISABLE(TS_CONFIG_DEDUCE_OUT)
  107. }
  108. macro _TS_TEST_FOR_ARGS(FOR_MOD, RELATIVE?"${CURDIR}":"${ARCADIA_ROOT}") {
  109. # we read testing modules' package.json during configuration,
  110. # so we have to include it to configuration cache key
  111. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $RELATIVE/$FOR_MOD/package.json)
  112. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $RELATIVE/$FOR_MOD/pnpm-lock.yaml)
  113. _VALIDATE_TS_TEST_FOR_ARGS($FOR_MOD $RELATIVE)
  114. _SET_TS_TEST_FOR_VARS($FOR_MOD)
  115. }
  116. macro _SETUP_EXTRACT_NODE_MODULES_RECIPE(FOR_PATH) {
  117. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_node_modules/recipe $FOR_PATH workspace_node_modules.tar)
  118. }
  119. macro _SETUP_EXTRACT_OUTPUT_TARS_RECIPE(FOR_PATH) {
  120. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_output_tars/recipe $FOR_PATH)
  121. }
  122. macro _SETUP_INSTALL_NODE_MODULES_RECIPE() {
  123. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/install_node_modules/recipe $NOTS_TOOL_BASE_ARGS --bundle no)
  124. }
  125. ### @usage: TS_TEST_CONFIG(Path)
  126. ###
  127. ### Macro sets the path to configuration file of the test runner.
  128. ###
  129. ### - Path - path to the config file.
  130. macro TS_TEST_CONFIG(Path) {
  131. SET(TS_TEST_CONFIG_PATH $Path)
  132. }
  133. _TS_TEST_SRCS_VALUE=
  134. _TS_TEST_EXTRA_SRCS_VALUE=
  135. ### @usage: TS_TEST_SRCS(DIRS...)
  136. ###
  137. ### Macro to define directories where the test source files should be located.
  138. ###
  139. ### - DIRS... - directories.
  140. macro TS_TEST_SRCS(DIRS...) {
  141. _GLOB(_TS_TEST_SRCS_VALUE ${suf=/**/*.$TS_TEST_EXTENSION:DIRS})
  142. SRCS($_TS_TEST_SRCS_VALUE)
  143. _GLOB(_TS_TEST_EXTRA_SRCS_VALUE ${suf=$TS_TEST_EXTRA_SRCS_MASK:DIRS})
  144. SRCS($_TS_TEST_EXTRA_SRCS_VALUE)
  145. }
  146. _TS_TEST_DATA_VALUE=
  147. _TS_TEST_DATA_DIRS_RENAME_VALUE=
  148. ### @usage: TS_TEST_DATA([RENAME] GLOBS...)
  149. ###
  150. ### Macro to add tests data (i.e. snapshots) used in testing to a bindir from curdir.
  151. ### Creates symbolic links to directories of files found by the specified globs.
  152. ###
  153. ### Parameters:
  154. ### - RENAME - adds ability to rename paths for tests data from curdir to bindir.
  155. ### For example if your tested module located on "module" path and tests data in "module/tests_data".
  156. ### Then you can be able to rename "tests_data" folder to something else - `RENAME tests_data:example`.
  157. ### As a result in your bindir will be created folder - "module/example" which is a symbolic link on "module/tests_data" in curdir.
  158. ### It is possible to specify multiple renaming rules in the following format "dir1:dir2;dir3/foo:dir4/bar", where "dir1" and "dir3" folders in curdir.
  159. ### - GLOBS... - globs to tests data files, symbolic links will be created to their folders. For example - "tests_data/**/*".
  160. macro TS_TEST_DATA(RENAME="", GLOBS...) {
  161. _GLOB(_TS_TEST_DATA_VALUE $GLOBS)
  162. SET(_TS_TEST_DATA_DIRS_RENAME_VALUE $RENAME)
  163. }
  164. ### @usage: TS_TEST_DEPENDS_ON_BUILD()
  165. ###
  166. ### Macro enables build and results unpacking for the module test is targeting.
  167. ### It is not required for most of the tests, but it might be needeed in some special cases.
  168. macro TS_TEST_DEPENDS_ON_BUILD() {
  169. ENABLE(_TS_TEST_DEPENDS_ON_BUILD)
  170. }
  171. _TS_TYPECHECK_VALUE=none
  172. _TS_TYPECHECK_TSCONFIG=
  173. macro NO_TS_TYPECHECK() {
  174. SET(_TS_TYPECHECK_VALUE none)
  175. }
  176. macro TS_TYPECHECK(TS_CONFG="") {
  177. ENABLE(_TS_TYPECHECK_VALUE)
  178. SET(_TS_TYPECHECK_TSCONFIG $TS_CONFG)
  179. }