DataDog / test-visibility-github-action

GitHub Action that installs Datadog Test Visibility
Apache License 2.0
3 stars 1 forks source link

Syntax error when running with vitest #23

Open aenand opened 5 days ago

aenand commented 5 days ago

Hello! I am trying to use this action to track tests for my Javascript app that uses vitest. When following the vitest section of the guide, the command to run the test errors out. Any idea what causes this?

Step:

    - run: npm run build --if-present
    - name: Configure Datadog Test Visibility
      uses: datadog/test-visibility-github-action@v2
      with:
        languages: js
        service: {{ service_name }}
        api_key: ${{ secrets.DD_API_KEY }}
        site: datadoghq.com # Change if your site is not US1
    - name: Run tests
      run: npm run test
      env: 
        NODE_OPTIONS: -r ${{ env.DD_TRACE_PACKAGE }} --import ${{ env.DD_TRACE_ESM_IMPORT }}

Error:

failed to load config from {{path_to_file}}/vitest.config.ts

⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯
SyntaxError: Identifier '$haml' has already been declared
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:168:18)
    at callTranslator (node:internal/modules/esm/loader:279:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:285:30)
juan-fernandez commented 1 day ago

hey @aenand !

This seems to be related to a known limitation with import-in-the-middle and ESM:

Until the upstream dependency (import-in-the-middle) is fixed, there's nothing we can do sadly. I'll keep you updated if there are any news.

In any case, if you could share a small reproducible case to confirm my assessment that'd be very useful. You can run your vitests directly without datadog/test-visibility-github-action (see instructions):

    - run: npm run build --if-present
    - name: Install dd-trace
      run: npm install --save-dev dd-trace
    - name: Run tests
      run: npm run test
      env: 
        NODE_OPTIONS: -r dd-trace/ci/init --import dd-trace/register.js
aenand commented 20 hours ago

Gotcha thanks! We use pnpm to manage dependencies so it seems like we might have to add the dd-trace package to our list. Appreciate the help!