Cucumber-js: 단계 μ •μ˜ 및 지원 μ½”λ“œμ—μ„œ κΈ°λ³Έ JS λͺ¨λ“ˆ 지원

에 λ§Œλ“  2020λ…„ 04μ›” 03일  Β·  13μ½”λ©˜νŠΈ  Β·  좜처: cucumber/cucumber-js

문제

κΈ°λ³Έ ECMAScript λͺ¨λ“ˆμ— μ •μ˜λœ 단계 μ •μ˜λ‘œ Cucumber.jsλ₯Ό μ‹€ν–‰ν•˜λ €κ³  ν•˜λ©΄( μ—¬κΈ° 에 μ„€λͺ…λœ λŒ€λ‘œ) ES λͺ¨λ“ˆμ—μ„œ CommonJS의 require() λ₯Ό μ‚¬μš©ν•˜κ³  μžˆλ‹€λŠ” 경고와 ν•¨κ»˜ μ‹œλ„κ°€ μ‹€νŒ¨ν•©λ‹ˆλ‹€.

Cucumber.js 버전: 6.0.5
λ…Έλ“œ 버전: 13.8.0

μž¬ν˜„ 단계

  1. npm init 및 npm i cucumber μ‚¬μš©ν•˜μ—¬ κΈ°λ³Έ NPM νŒ¨ν‚€μ§€ 디렉토리 μ„€μ •

    • package.json νŒŒμΌμ— "type": "module" λ₯Ό μ„€μ •ν•˜μ—¬ JS 파일이 κΈ°λ³Έ λͺ¨λ“ˆλ‘œ μ²˜λ¦¬λ˜λ„λ‘ ν•©λ‹ˆλ‹€.

  2. κΈ°λ³Έ κΈ°λŠ₯ 파일 features/mjs.feature :

    Feature: Native JS Modules
    
        Scenario: Load a native JS module step definition
            Given I have 42 cucumbers in my belly
    
  3. κΈ°λ³Έ 단계 μ •μ˜ 파일 features/step_definitions.js :

    import { Given } from "cucumber";
    
    Given("I have {int} cucumbers in my belly", function (cucumberCount) {
        console.log("Step parsed.");
    });
    
  4. Cucumber μ‹€ν–‰ μ‹œλ„:

    $ ./node_modules/.bin/cucumber-js
    

μ˜ˆμƒ κ²°κ³Ό

단계 μ •μ˜ λͺ¨λ“ˆμ„ λ‘œλ“œν•˜μ—¬ 단계λ₯Ό ꡬ문 λΆ„μ„ν•˜λŠ” 데 μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.

μ‹€μ œ κ²°κ³Ό

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /some/path/cucumbertest/features/step_definitions.js
require() of ES modules is not supported.
require() of /some/path/cucumbertest/features/step_definitions.js from /some/path/cucumbertest/node_modules/cucumber/lib/cli/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename step_definitions.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /some/path/cucumbertest/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:13)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at /some/path/cucumbertest/node_modules/cucumber/lib/cli/index.js:119:42
    at Array.forEach (<anonymous>)
    at Cli.getSupportCodeLibrary (/some/path/cucumbertest/node_modules/cucumber/lib/cli/index.js:119:22)
    at Cli.run (/some/path/cucumbertest/node_modules/cucumber/lib/cli/index.js:141:37)
    at async Object.run [as default] (/some/path/cucumbertest/node_modules/cucumber/lib/cli/run.js:30:14)

폐쇄

κ·Έλ§Œν•œ κ°€μΉ˜κ°€ μžˆλŠ” 만큼 Cucumber.js νŒ€μ΄ 이 ν”„λ‘œμ νŠΈμ— νˆ¬μž…ν•œ μž‘μ—…μ— 정말 κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€. 이 ν”„λ‘œμ νŠΈλŠ” λ‚˜μ™€ λ‚΄ νšŒμ‚¬μ˜ μ£Όμš” μžμ‚°μ΄μ—ˆμŠ΅λ‹ˆλ‹€. 우리 νŒ€μ€ λ„€μ΄ν‹°λΈŒ JS λͺ¨λ“ˆμ—μ„œ 일뢀 곡유 μ‘μš© ν”„λ‘œκ·Έλž¨ ꡬ성 μš”μ†Œλ₯Ό λΉŒλ“œν•˜λŠ” 데 μ‹œκ°„μ„ νˆ¬μžν–ˆμœΌλ©° μ΅œκ·ΌκΉŒμ§€ (κ°€μž₯ μ΅œμ‹  λ¬Έμ„œμ˜ import ꡬ문을 기반으둜) 이 ν•­λͺ©μ΄ Cucumber와 ν•¨κ»˜ μž‘λ™ν•  것이라고 κ°€μ •ν–ˆμŠ΅λ‹ˆλ‹€. ν…ŒμŠ€νŠΈ ν”„λ ˆμž„μ›Œν¬μ™€ ν†΅ν•©ν•˜κΈ° μ‹œμž‘ν–ˆμŠ΅λ‹ˆλ‹€. ν•˜μ§€λ§Œ 그렇지 μ•Šμ€ 것 κ°™μŠ΅λ‹ˆλ‹€. 곡유 ꡬ성 μš”μ†Œκ°€ 이미 μž‘μ„±λ˜μ–΄ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ λ‹€λ₯Έ 뢀뢄에 ν†΅ν•©λ˜μ–΄ μžˆμœΌλ―€λ‘œ μƒν˜Έ μš΄μš©μ„± 문제 λ•Œλ¬Έμ— CommonJS둜 μž‘μ„±λœ 단계 μ •μ˜ 및 지원 μ½”λ“œλ§Œ μ‚¬μš©ν•˜λŠ” 것을 κΊΌλ¦½λ‹ˆλ‹€.

이 μž‘μ—…μ„ μˆ˜ν–‰ν•˜λ €κ³  μ‹œλ„ν•œ λ‹€λ₯Έ 것듀이 ν¬ν•¨λ˜μ—ˆμŠ΅λ‹ˆλ‹€ ...

  • Node.js κ·œμΉ™μ— 따라 κΈ°λ³Έ λͺ¨λ“ˆ νŒŒμΌμ— .mjs ν™•μž₯자λ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€(이둜 인해 Cucumber의 μžλ™ λ‘œλ“œ λ…Όλ¦¬μ—μ„œ κ°„κ³Όλ˜κ³  --require λ₯Ό μ‚¬μš©ν•˜μ—¬ 단계 μ •μ˜ λͺ¨λ“ˆμ„ λͺ…μ‹œμ μœΌλ‘œ λ‘œλ“œν•˜λ©΄ Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
  • 동적 import() ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜λŠ” CJS λͺ¨λ“ˆμ˜ κΈ°λ³Έ λͺ¨λ“ˆ λž˜ν•‘; λ¬Έμ œλŠ” 이 μ ‘κ·Ό 방식이 비동기식이며 CJS λͺ¨λ“ˆμ—μ„œ κ°€μ Έμ˜€κΈ° 약속을 내보낸 κ²½μš°μ—λ„ CucumberλŠ” ν•΄λ‹Ή 단계가 μ •μ˜λ˜μ§€ μ•Šμ€ κ²ƒμœΌλ‘œ ν‘œμ‹œλ˜κΈ° λ•Œλ¬Έμ— 계속 μ§„ν–‰ν•˜κΈ° 전에 ν•΄λ‹Ή 약속이 해결될 λ•ŒκΉŒμ§€ 기닀리지 μ•ŠλŠ” κ²ƒμœΌλ‘œ λ³΄μž…λ‹ˆλ‹€(단계 μ •μ˜κ°€ λ„€μ΄ν‹°λΈŒ λͺ¨λ“ˆμ— 아직 λ“±λ‘λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€).

제 λŠ₯λ ₯ λ²”μœ„ λ‚΄μ—μ„œ 이 문제λ₯Ό ν•΄κ²°ν•˜λŠ” 데 도움이 λ˜λ„λ‘ PR을 μ œμΆœν•˜κ³  μ‹Άμ§€λ§Œ Cucumber.js의 λ‚΄λΆ€ μž‘λ™μ— μ΅μˆ™ν•˜μ§€ μ•ŠμœΌλ―€λ‘œ λˆ„κ΅°κ°€ μ €λ₯Ό μ˜¬λ°”λ₯Έ λ°©ν–₯으둜 μ•ˆλ‚΄ν•΄ μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€.

accepted enhancement

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

λ‚˜λŠ” 이것이 μž₯기적으둜 ν‘œμ€€μ΄ 될 κ²ƒμœΌλ‘œ μ˜ˆμƒν•˜κΈ° λ•Œλ¬Έμ— .js ν™•μž₯κ³Ό "type":"module" μ‚¬μš©ν•©λ‹ˆλ‹€.

λͺ¨λ“  13 λŒ“κΈ€

였이-jsκ°€ ESMκ³Ό ν•¨κ»˜ μž‘λ™ν•˜λ„λ‘ ν•˜κ³  μ‹ΆμŠ΅λ‹ˆλ‹€. μš°λ¦¬λŠ” 이미 그것에 λŒ€ν•΄ λͺ‡ 가지 λ‹€λ₯Έ 문제λ₯Ό μ—΄μ—ˆμŠ΅λ‹ˆλ‹€.

였이-jsκ°€ λ°˜ν™˜λœ 약속을 μš”κ΅¬ν•˜κ³  기닀리지 μ•Šκ³  import λ₯Ό μ‚¬μš©ν•˜λ„λ‘ ν•˜λŠ” CLI μ˜΅μ…˜μ„ λ§Œλ“€ 수 μžˆμŠ΅λ‹ˆλ‹€.

μΆ”κ°€ν•œ μ˜ˆμ œκ°€ 주어지면 이에 λŒ€ν•œ ν…ŒμŠ€νŠΈ μΌ€μ΄μŠ€λ₯Ό μΆ”κ°€ν•˜κ³  톡과할 수 μžˆλ„λ‘ μž‘μ—…ν•  수 μžˆμŠ΅λ‹ˆλ‹€. μ „ν™˜μ„ μ‹€ν—˜ν•˜λ €λ©΄ 약속을 κ°€μ Έμ™€μ„œ κΈ°λ‹€λ €μ•Ό ν•˜κ³  λ‹€λ₯Έ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€.

β‹Š> ~/p/test ./node_modules/.bin/cucumber-js                                21:05:22
(node:7422) ExperimentalWarning: The ESM module loader is experimental.
file:///test/features/steps.js:1
import { Given } from "cucumber";
         ^^^^^
SyntaxError: The requested module 'cucumber' does not provide an export named 'Given'
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:92:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:107:20)
    at async Loader.import (internal/modules/esm/loader.js:176:24)
    at async Promise.all (index 0)
    at async Cli.getSupportCodeLibrary (/test/node_modules/cucumber/lib/cli/index.js:119:5)
    at async Cli.run (/test/node_modules/cucumber/lib/cli/index.js:141:32)
    at async Object.run [as default] (/test/node_modules/cucumber/lib/cli/run.js:30:14)

단계 μ •μ˜ λ¬Έμ„œμ—μ„œ 예제(μ•½κ°„ μˆ˜μ •λ¨)λ₯Ό κ°€μ Έμ™”μ§€λ§Œ λ‹Ήμ‹  말이 λ§žμ•„, 쓰여진 λŒ€λ‘œ μž‘λ™ν•˜μ§€ μ•Šμ„ κ²ƒμž…λ‹ˆλ‹€. Cucumber.jsλŠ” CommonJS λͺ¨λ“ˆμ΄κΈ° λ•Œλ¬Έμ— κΈ°λ³Έ λ‚΄λ³΄λ‚΄κΈ°λ§Œ μ œκ³΅ν•©λ‹ˆλ‹€. λ‹¨κΈ°μ μœΌλ‘œλŠ” λͺ¨λ“ˆ 기본값을 κ°€μ Έμ˜¨ λ‹€μŒ λ‹€μŒμ—μ„œ Given/When/Then λ©”μ„œλ“œμ— μ•‘μ„ΈμŠ€ν•  κ²ƒμž…λ‹ˆλ‹€.

import cucumber from "cucumber";

cucumber.Given(...);

μž₯기적으둜 μ˜€μ΄μ— 여기에 ν‘œμ‹œλœ κ²ƒμ²˜λŸΌ import 및 require에 λŒ€ν•œ λ³„λ„μ˜ μ§„μž…μ μ΄ 있으면 쒋을 κ²ƒμž…λ‹ˆλ‹€.

λ΄μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€. κ·Έλ§Œν•œ κ°€μΉ˜κ°€ 있기 λ•Œλ¬Έμ— Cucumberμ—κ²Œ μš”κ΅¬ν•˜λŠ” λŒ€μ‹  κ°€μ Έ μ˜€λ„λ‘ μ§€μ‹œν•˜λŠ” CLI μ˜΅μ…˜μ΄ μ €μ—κ²Œ μ ν•©ν•©λ‹ˆλ‹€. Cucumberκ°€ ν™•μž₯μžκ°€ .cjs 및 .mjs인 지원 νŒŒμΌμ„ μ°Ύκ³  이λ₯Ό 각각 CommonJS 및 κΈ°λ³Έ λͺ¨λ“ˆλ‘œ μžλ™ μ²˜λ¦¬ν•˜λŠ” κ²½μš°μ—λ„ 쒋을 κ²ƒμž…λ‹ˆλ‹€.

νŽΈμ§‘: ν•  수만 μžˆλ‹€λ©΄ 기꺼이 λ„μ™€λ“œλ¦΄ 수 μžˆλ‹€λŠ” 점을 λ‹€μ‹œ ν•œ 번 λ§μ”€λ“œλ¦¬κ³  μ‹ΆμŠ΅λ‹ˆλ‹€. μ˜¬λ°”λ₯Έ λ°©ν–₯으둜 λ‚˜λ₯Ό κ°€λ¦¬μΌœ μ£Όμ‹­μ‹œμ˜€.

λ‚˜λŠ” μ•„λ§ˆλ„ λͺ¨λ“ˆ 기본값을 κ°€μ Έμ˜¨ λ‹€μŒ κ·Έλ‘œλΆ€ν„° Given/When/Then λ©”μ†Œλ“œμ— μ•‘μ„ΈμŠ€ν•  κ²ƒμž…λ‹ˆλ‹€.
"였이"μ—μ„œ 였이 μˆ˜μž…;
였이.주어진(...);

μž‘λ™ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. 같은 λ©”μ‹œμ§€κ°€ λ‚˜νƒ€λ‚©λ‹ˆλ‹€.
package.json에 "type": "module"이 있고 λ‚˜λ¨Έμ§€ ν”„λ‘œμ νŠΈμ—μ„œλŠ” λͺ¨λ“ˆμ„ μ‚¬μš©ν•˜κ³  μžˆμœΌλ―€λ‘œ λ³€κ²½ν•˜λŠ” 것은 μ˜΅μ…˜μ΄ μ•„λ‹™λ‹ˆλ‹€.

λ‹€μŒ 쀑 ν•˜λ‚˜λ₯Ό μ‚¬μš©ν•˜λŠ” 경우:

import cucumber from '@cucumber/cucumber';
// OR
import { When } from '@cucumber/cucumber';

원본 κ²Œμ‹œλ¬Όκ³Ό λ™μΌν•œ 였λ₯˜ λ©”μ‹œμ§€κ°€ λ‚˜νƒ€λ‚©λ‹ˆλ‹€.
λ‚΄κ°€ λ³€κ²½ν•˜λ©΄

const cucumber = require('@cucumber/cucumber');

그런 λ‹€μŒμ΄ λ©”μ‹œμ§€κ°€ λ‚˜νƒ€λ‚©λ‹ˆλ‹€.

λŒ€μ‹  /some/path/cucumbertest/features/step_definitions.js의 이름을 .cjs둜 λλ‚˜λ„λ‘ λ³€κ²½ν•˜κ±°λ‚˜ import()λ₯Ό μ‚¬μš©ν•˜λ„λ‘ ν•„μˆ˜ μ½”λ“œλ₯Ό λ³€κ²½ν•˜κ±°λ‚˜ project/package.jsonμ—μ„œ "type": "module"을 μ œκ±°ν•˜μ‹­μ‹œμ˜€.

step_definitions.js 을 _either_ step_definitions.cjs λ˜λŠ” step_definitions.mjs ν•˜λ©΄ λ¬΄μ‹œλ˜κ³  μ˜€μ΄λ‘œλΆ€ν„° λ‚΄ 단계에 λŒ€ν•œ μŠ€ν…μ„ μƒμ„±ν•˜λΌλŠ” 일반 λ©”μ‹œμ§€λ₯Ό λ°›μŠ΅λ‹ˆλ‹€.

UUUUUU

Failures:

1) Scenario: Empty Payload # spec\cucumber\features\users\create\main.feature:4
   ? When the client creates a POST request to /users
       Undefined. Implement with the following snippet:

         When('the client creates a POST request to \/users', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

... etc

νŒŒμΌμ„ μ™„μ „νžˆ μ‚­μ œν•΄λ„ λ˜‘κ°™μ€ λ©”μ‹œμ§€κ°€ ν‘œμ‹œλ˜λ―€λ‘œ λΆ„λͺ…νžˆ λ¬΄μ‹œλ©λ‹ˆλ‹€.

μ†”λ£¨μ…˜(μΌμ’…μ˜)

κ²°κ΅­ "type": "module"이 μžˆλŠ” ν”„λ‘œμ νŠΈμ—μ„œ 였이λ₯Ό μ‹€ν–‰ν•  수 μžˆλŠ” μœ μΌν•œ 방법은 "type": "module" 없이 λ³„λ„μ˜ specpackage.json을 λ§Œλ“€κ³  spec/node_modules 였이λ₯Ό μ„€μΉ˜ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€

μ§€κΈˆκΉŒμ§€λŠ” μž‘λ™ν•˜λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. μ‹€μ œ ν…ŒμŠ€νŠΈλ₯Ό λ§Œλ“  후에도 μ—¬μ „νžˆ μž‘λ™ν•˜λŠ”μ§€ λ΄…μ‹œλ‹€.

κ΄€λ¦¬μžμ—κ²Œ: μ˜€μ΄λŠ” 처음 μ‚¬μš©ν•˜λŠ”λ° μ§€κΈˆκΉŒμ§€ μ’‹μ•„ν•©λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ 이것은 μ‹€μ œλ‘œ λ‚΄ 진행에 흠집을 λƒˆμŠ΅λ‹ˆλ‹€. μ˜€ν›„μ— 였이λ₯Ό λ°°μš°λŠ” λŒ€μ‹  μˆ˜μž…ν’ˆμ„ λ””λ²„κΉ…ν•˜λŠ” 데 λ³΄λƒˆμŠ΅λ‹ˆλ‹€. ES6 κ°€μ Έμ˜€κΈ°μ™€ CJSλ₯Ό λͺ¨λ‘ μ§€μ›ν•˜λŠ” 라이브러리λ₯Ό λ§Œλ“œλŠ” 것이 μ–Όλ§ˆλ‚˜ μ„±κ°€μ‹  일인지 μ••λ‹ˆλ‹€.

κ°€λŠ₯ν•œ μ†”λ£¨μ…˜:
두 번째 dist νŒŒμΌμ„ μƒμ„±ν•˜λ©΄ CJS 및 ES6 λΉŒλ“œλ₯Ό λ™μ‹œμ— κ²Œμ‹œν•  수 μžˆμŠ΅λ‹ˆλ‹€.

dist/cucumber.js
dist/cucumber.module.js

그런 λ‹€μŒ package.json에 λ‹€μŒ 쀄을 μΆ”κ°€ν•©λ‹ˆλ‹€.

"λͺ¨λ“ˆ": "dist/cucumber.module.js"

μ΄λ ‡κ²Œ ν•˜λ©΄ λ…Έλ“œκ°€ ES6 κ°€μ Έμ˜€κΈ°λ₯Ό ν•΄κ²°ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

이 μž‘μ—…μ„ μˆ˜ν–‰ν•˜λŠ” 더 λ‚˜μ€ 방법이 μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€. λ‚˜λ„ κ·Έ λ¬Έμ œκ°€ 있고 importsλŠ” commonJS와 ν•¨κ»˜ μ‚¬μš©ν•  수 μ—†κΈ° λ•Œλ¬Έμ— μ‚¬μš©ν•΄μ•Ό ν•  κ²ƒμž…λ‹ˆλ‹€.
https://nodejs.org/api/esm.html#esm_import_expressions

μ–΄λ””μ—λ‚˜...

Cucumberκ°€ ESλ₯Ό μ‚¬μš©ν•˜λŠ” 데 도움이 λ˜λŠ” ν”Œλž˜κ·Έλ₯Ό κ°€μ§ˆ 수 μžˆλŠ” 방법이 μžˆμŠ΅λ‹ˆκΉŒ?

이에 관심이 μžˆλŠ” μ‚¬λžŒλ“€μ„ μœ„ν•œ λΉ λ₯Έ 정보: μ˜€μ΄κ°€ μžˆλŠ” ν”„λ‘œμ νŠΈμ—μ„œ ESM을 μ‚¬μš©ν•  λ•Œ λ‹€μŒμ„ μˆ˜ν–‰ν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?

  • .js ν™•μž₯ 및 "type":"module"
  • .mjs ν™•μž₯ μ‚¬μš©
  • λ‹€λ₯Έ 것?

감사 ν•΄μš”!

λͺ¨ν˜Έμ„±μ„ ν”Όν•˜κΈ° μœ„ν•΄ λͺ¨λ“  JavaScript νŒŒμΌμ— .mjs 및 .cjs ν™•μž₯자λ₯Ό μ‚¬μš©ν•˜λŠ” κ·œμΉ™μ„ λ”°λ₯΄λŠ” κ²½ν–₯이 있으며 이 κ²½μš°μ—λ„ κ·Έλ ‡κ²Œ ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ ν”„λ‘œμ νŠΈ μˆ˜μ€€μ—μ„œ "type": "module"을 μ„€μ •ν•˜κ³  더 λ§Žμ€ μ‚¬μš©μžμ—κ²Œ 더 λ‚˜μ€ μ†”λ£¨μ…˜μΈ 경우 .js 파일둜 λ‚¨κ²¨λ‘λŠ” 것은 큰 뢈편이 없을 κ²ƒμž…λ‹ˆλ‹€.

λ‚˜λŠ” 이것이 μž₯기적으둜 ν‘œμ€€μ΄ 될 κ²ƒμœΌλ‘œ μ˜ˆμƒν•˜κΈ° λ•Œλ¬Έμ— .js ν™•μž₯κ³Ό "type":"module" μ‚¬μš©ν•©λ‹ˆλ‹€.

ν”Όλ“œλ°±μ— κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€ @adamlacoste @looeee

@davidjgoss #1589λ₯Ό λ³‘ν•©ν•˜λ©΄ ν•΄λ‹Ή λ¬Έμ œκ°€ μ’…λ£Œλ  수 μžˆμŠ΅λ‹ˆκΉŒ? μ•„λ‹ˆλ©΄ λ‹€λ₯Έ 것이 ν•„μš”ν•©λ‹ˆκΉŒ?

넛지 @aurelien-reeves에 κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€!

@cucumber/cucumber 의 버전 7.2.0은 이제 npm에 있으며 여기에 λ¬Έμ„œμ— μ„€λͺ…λœ λŒ€λ‘œ ESM에 λŒ€ν•œ μ‹€ν—˜μ  지원이 ν¬ν•¨λ©λ‹ˆλ‹€.
https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#es-modules-experimental-nodejs-12

관심 μžˆλŠ” μ‚¬λžŒμ΄ μ‹œλ„ν•΄ 보고 λ³΄κ³ ν•œ λ‚΄μš©μ΄ ν›Œλ₯­ν•  수 μžˆλ‹€λ©΄. λ‚˜λŠ” 여기에 μ•„μ£Ό μ΅œμ†Œν•œμ˜ 예제 ν”„λ‘œμ νŠΈλ₯Ό λ„£μ—ˆμŠ΅λ‹ˆλ‹€.
https://github.com/davidjgoss/cucumber-esm-example

ν•œ κ³³μ—μ„œ 초기 ν”Όλ“œλ°±μ„ λ°›κΈ° μœ„ν•΄ 이 문제λ₯Ό μž μ‹œ μ—΄μ–΄ λ‘κ²Œ λ˜μ–΄ κΈ°μ©λ‹ˆλ‹€.

λ”°λΌμ„œ 이 λ³€κ²½μœΌλ‘œ 인해 νŠΉμ • ν•­λͺ©μ„ 직접 require ν•˜λŠ” 타사 ν”„λ ˆμž„μ›Œν¬ 및 포맷터에 λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€(μ§„μž… 지점과 λ°˜λŒ€). 기본적으둜 7.1.0으둜 λ˜λŒλ¦¬λŠ” 7.2.1을 μΆœμ‹œν•˜μ—¬ ν•΄λ‹Ή μ‚¬μš©μžμ˜ 차단을 ν•΄μ œν–ˆμŠ΅λ‹ˆλ‹€. 원인을 νŒŒκ³ λ“€μ–΄ ESM을 계속 μ§€μ›ν•˜λ©΄μ„œ 이λ₯Ό ν”Όν•  수 μžˆλŠ”μ§€ ν™•μΈν•˜κ² μŠ΅λ‹ˆλ‹€. κ·Έ λ™μ•ˆ, 그것이 λ‹Ήμ‹ μ—κ²Œ 영ν–₯을 λ―ΈμΉ˜μ§€ μ•ŠλŠ”λ‹€λ©΄, 7.2.0은 μ—¬μ „νžˆ β€‹β€‹μ‹€ν—˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

λ‚˜λŠ” --esm ν”Œλž˜κ·Έμ™€ ν•¨κ»˜ v7.2.0 μ—κ²Œ 기회λ₯Ό μ£Όλ €κ³  ν–ˆμŠ΅λ‹ˆλ‹€. ESM으둜 λ³€ν™˜ν•˜λ €λŠ” νŒ¨ν‚€μ§€μ— λŒ€ν•œ ν…ŒμŠ€νŠΈμ—μ„œ testdouble을 μ‚¬μš©ν•©λ‹ˆλ‹€.

μ‚¬μš©ν•˜κΈ° μœ„ν•΄μ„œλŠ” td.replaceEsm , λ‘œλ”μ²˜λŸΌ μ‚¬μš©λ˜μ–΄μ•Όν•©λ‹ˆλ‹€ --loader=testdouble . 였이 cli에 직접 λ‘œλ”λ₯Ό μ œκ³΅ν•˜λ €κ³  ν•˜λ©΄ λ‹€μŒ 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.

> cucumber-js test/integration --esm --loader=testdouble

error: unknown option '--loader=testdouble'

ν•΄λ‹Ή μ˜΅μ…˜μ„ μ‚¬μš©ν•  수 μ—†μ—ˆκΈ° λ•Œλ¬Έμ— NODE_OPTIONS 둜 μ‹œλ„ν–ˆμŠ΅λ‹ˆλ‹€.

> NODE_OPTIONS='--loader=testdouble' cucumber-js test/integration --esm

(node:62231) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /path/to/project/node_modules/@cucumber/cucumber/bin/cucumber-js
    at defaultGetFormat (internal/modules/esm/get_format.js:71:15)
    at getFormat (file:///path/to/project/node_modules/quibble/lib/quibble.mjs:65:12)
    at Loader.getFormat (internal/modules/esm/loader.js:104:42)
    at Loader.getModuleJob (internal/modules/esm/loader.js:242:31)
    at async Loader.import (internal/modules/esm/loader.js:176:17)
    at async Object.loadESM (internal/process/esm_loader.js:68:5) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

참고둜 이것은 v14.17.0 λ…Έλ“œμ— λŒ€ν•œ κ²ƒμ΄μ—ˆμŠ΅λ‹ˆλ‹€.

이것이 NODE_OPTIONS μ ‘κ·Ό 방식과 ν•¨κ»˜ μž‘λ™ν•˜λ©΄ μ’‹κ² μ§€λ§Œ μ΄μƒμ μœΌλ‘œλŠ” --loader μ˜΅μ…˜μ΄ 일뢀 ν…ŒμŠ€νŠΈ ν”„λ ˆμž„μ›Œν¬κ°€ μ§€μ›ν•˜κΈ° μ‹œμž‘ν•œ κ²ƒμ²˜λŸΌ cliμ—μ„œ 직접 μ§€μ›λ©λ‹ˆλ‹€. ESM 지원에 μ ‘κ·Όν•˜λŠ” λ‹€μŒ λ²„μ „μ—μ„œ μ΄λŸ¬ν•œ μ ‘κ·Ό 방식을 κ³ λ €ν•˜μ‹­μ‹œμ˜€. :)

v7.2.0 둜 μž‘μ—…ν•  κ²ƒμœΌλ‘œ μ˜ˆμƒλ˜λŠ” λ‘œλ”λ₯Ό μ •μ˜ν•˜λŠ” 방법이 μžˆμŠ΅λ‹ˆκΉŒ?

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰