ts_test.conf 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 TS)
  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 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 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 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=Bundle
  96. .PEERDIR_POLICY=as_build_from
  97. # .fake tells builder to not materialize it in results
  98. SET(MODULE_SUFFIX .ts_test.fake)
  99. # include processor works only for TS tag
  100. SET(MODULE_TAG TS)
  101. SET(MODULE_LANG TS)
  102. # we read erm-packages.json during configuration, so we have to include it to configuration cache key
  103. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${ARCADIA_ROOT}/$ERM_PACKAGES_PATH)
  104. # parse module args
  105. _TS_TEST_FOR_ARGS($MODULE_ARGS_RAW)
  106. # Set PM values from TS_TEST_FOR_DIR
  107. _SET_PACKAGE_MANAGER()
  108. # we don't want to have TS outputs for tests
  109. DISABLE(TS_CONFIG_DEDUCE_OUT)
  110. }
  111. macro _TS_TEST_FOR_ARGS(FOR_MOD, RELATIVE?"${CURDIR}":"${ARCADIA_ROOT}") {
  112. # we read testing modules' package.json during configuration,
  113. # so we have to include it to configuration cache key
  114. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $RELATIVE/$FOR_MOD/package.json)
  115. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $RELATIVE/$FOR_MOD/pnpm-lock.yaml)
  116. _VALIDATE_TS_TEST_FOR_ARGS($FOR_MOD $RELATIVE)
  117. _SET_TS_TEST_FOR_VARS($FOR_MOD)
  118. }
  119. macro _SETUP_EXTRACT_NODE_MODULES_RECIPE(FOR_PATH) {
  120. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_node_modules/recipe $FOR_PATH workspace_node_modules.tar)
  121. }
  122. macro _SETUP_EXTRACT_OUTPUT_TARS_RECIPE(FOR_PATH) {
  123. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_output_tars/recipe $FOR_PATH)
  124. }
  125. macro _SETUP_INSTALL_NODE_MODULES_RECIPE() {
  126. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/install_node_modules/recipe $NOTS_TOOL_BASE_ARGS --bundle no)
  127. }
  128. ### @usage: TS_TEST_CONFIG(Path)
  129. ###
  130. ### Macro sets the path to configuration file of the test runner.
  131. ###
  132. ### - Path - path to the config file.
  133. macro TS_TEST_CONFIG(Path) {
  134. SET(TS_TEST_CONFIG_PATH $Path)
  135. }
  136. _TS_TEST_SRCS_VALUE=
  137. _TS_TEST_EXTRA_SRCS_VALUE=
  138. ### @usage: TS_TEST_SRCS(DIRS...)
  139. ###
  140. ### Macro to define directories where the test source files should be located.
  141. ###
  142. ### - DIRS... - directories.
  143. macro TS_TEST_SRCS(DIRS...) {
  144. _GLOB(_TS_TEST_SRCS_VALUE ${suf=/**/*.$TS_TEST_EXTENSION:DIRS})
  145. SRCS($_TS_TEST_SRCS_VALUE)
  146. _GLOB(_TS_TEST_EXTRA_SRCS_VALUE ${suf=$TS_TEST_EXTRA_SRCS_MASK:DIRS})
  147. SRCS($_TS_TEST_EXTRA_SRCS_VALUE)
  148. }
  149. _TS_TEST_DATA_VALUE=
  150. _TS_TEST_DATA_DIRS_RENAME_VALUE=
  151. ### @usage: TS_TEST_DATA([RENAME] GLOBS...)
  152. ###
  153. ### Macro to add tests data (i.e. snapshots) used in testing to a bindir from curdir.
  154. ### Creates symbolic links to directories of files found by the specified globs.
  155. ###
  156. ### Parameters:
  157. ### - RENAME - adds ability to rename paths for tests data from curdir to bindir.
  158. ### For example if your tested module located on "module" path and tests data in "module/tests_data".
  159. ### Then you can be able to rename "tests_data" folder to something else - `RENAME tests_data:example`.
  160. ### As a result in your bindir will be created folder - "module/example" which is a symbolic link on "module/tests_data" in curdir.
  161. ### 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.
  162. ### - GLOBS... - globs to tests data files, symbolic links will be created to their folders. For example - "tests_data/**/*".
  163. macro TS_TEST_DATA(RENAME="", GLOBS...) {
  164. _GLOB(_TS_TEST_DATA_VALUE $GLOBS)
  165. SET(_TS_TEST_DATA_DIRS_RENAME_VALUE $RENAME)
  166. }
  167. ### @usage: TS_TEST_DEPENDS_ON_BUILD()
  168. ###
  169. ### Macro enables build and results unpacking for the module test is targeting.
  170. ### It is not required for most of the tests, but it might be needeed in some special cases.
  171. macro TS_TEST_DEPENDS_ON_BUILD() {
  172. ENABLE(_TS_TEST_DEPENDS_ON_BUILD)
  173. }
  174. # TS_TYPECHECK
  175. _TS_TYPECHECK_VALUE=none
  176. _TS_TYPECHECK_TSCONFIG=
  177. macro NO_TS_TYPECHECK() {
  178. SET(_TS_TYPECHECK_VALUE none)
  179. }
  180. macro TS_TYPECHECK(TS_CONFG="") {
  181. ENABLE(_TS_TYPECHECK_VALUE)
  182. SET(_TS_TYPECHECK_TSCONFIG $TS_CONFG)
  183. }
  184. # TS_STYLELINT
  185. _TS_STYLELINT_VALUE=no
  186. _TS_STYLELINT_CONFIG=
  187. _TS_STYLELINT_FILES=
  188. macro TS_STYLELINT(_CONFIG) {
  189. ENABLE(_TS_STYLELINT_VALUE)
  190. SET(_TS_STYLELINT_CONFIG $_CONFIG)
  191. _GLOB(_TS_STYLELINT_FILES **/*(.css|.scss|.less) EXCLUDE $TS_EXCLUDE_DIR_GLOB $TS_COMMON_OUTDIR_GLOB $TS_GLOB_EXCLUDE_ADDITIONAL)
  192. }