> For the complete documentation index, see [llms.txt](https://ecfmg.gitbook.io/azure-serverless-quickstart/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ecfmg.gitbook.io/azure-serverless-quickstart/application-design/jest-tests.md).

# Jest Tests

Data Access Project

Initialize Jest by running these commands

{% code title="terminal : azure-quickstart/data-access" %}

```bash
npm i -D jest typescript
npm i -D ts-jest @types/jest
npx ts-jest config:init
```

{% endcode %}

Confgure jest config

{% code title="azure-quickstart/data-access/jest.config.js" %}

```bash
module.exports = {
  roots: ["<rootDir>/."],
  preset: 'ts-jest',
  testEnvironment: 'node',
  testMatch: ['**/**/*.test.ts'],
    coverageReporters: ['json', 'lcov'],
    coverageDirectory: 'coverage',
    collectCoverageFrom: [
      "**/*.{js,jsx,ts}",
      "!**/node_modules/**",
      "!**/dist/**"
    ]
};
```

{% endcode %}

Configure package.json

{% code title="azure-quickstart/data-access/package.json" %}

```bash
...
  "scripts": {
    "test:ci": "npx jest --watchAll=false --coverage=true",
    "test": "npx jest --watch"
  },

...
```

{% endcode %}

Configure yaml

{% code title="azure-quickstart/data-access/azure-pipelines.yml" %}

```yaml
>> UPDATE NPM BUILD TASK
>> Add 'npm run test:ci' before build production
...
    # Build project and run tests
    - task: Bash@3
      displayName: 'NPM: Prepare binaries and run tests'
      inputs:
        targetType: 'inline'
        script: |
          export NODE_OPTIONS=--max_old_space_size=16384
          npm ci
          npm run test:ci
          npm run build:production
        workingDirectory: 'data-access'
...

>> UPDATE SONAR CLOUD PREPARE TASK
>> Add sonar.javascript.lcov.reportPaths to extraProperties
...
    # Set up SonarCloud
    - task: SonarCloudPrepare@1
      displayName: 'SonarCloud: Prepare analysis configuration'
      inputs:
        SonarCloud: 'sonarcloud'
        organization: 'simnova'
        scannerMode: 'CLI'
        configMode: 'manual'
        cliProjectKey: 'sharethrift-data-access'
        cliProjectName: 'sharethrift-data-access'
        cliSources: './data-access'
        extraProperties: |
          sonar.javascript.lcov.reportPaths=$(System.DefaultWorkingDirectory)/data-access/coverage/lcov.info
```

{% endcode %}

Configure .gitignore

{% code title=".gitignore" %}

```yaml
...
...
/coverage
```

{% endcode %}

References:


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ecfmg.gitbook.io/azure-serverless-quickstart/application-design/jest-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
