Skip to content

Conversation

@josecelano
Copy link
Member

@josecelano josecelano commented Jul 5, 2023

I'm trying to set up the basic scaffolding for unit testing, but I have not been able so far.

I wanted to add unit tests to sanitize HTML functions in this PR.

It's not working because it can't resolve nuxt paths like #build, #imports, ...

This PR includes the configuration I've been trying so far.

Links

@josecelano josecelano added the Help Wanted More Contributions are Appreciated label Jul 5, 2023
@josecelano josecelano requested a review from da2ce7 July 5, 2023 17:10
@josecelano
Copy link
Member Author

I've tried to fix hundreds of errors. The lastest one is:

 npm run test

> test
> jest --config jest.config.ts --coverage

 FAIL  src/domain/services/sanitizer.test.ts
  ● Test suite failed to run

    Configuration error:
    
    Could not locate module #build/nuxt.config.mjs mapped as:
    /home/josecelano/Documents/git/committer/me/github/torrust/torrust-index-frontend/.nuxt/$1.
    
    Please check your configuration for these entries:
    {
      "moduleNameMapper": {
        "/^#build\/(.*)$/": "/home/josecelano/Documents/git/committer/me/github/torrust/torrust-index-frontend/.nuxt/$1"
      },
      "resolver": undefined
    }

      1 | import { PublicSettings, Category, TokenResponse, TorrentTag } from "torrust-index-types-lib";
      2 | import { Rest } from "torrust-index-api-lib";
    > 3 | import { useRuntimeConfig, useState } from "#app";
        | ^
      4 | import { notify } from "notiwind-ts";
      5 |
      6 | export const useRestApi = () => useState<Rest>("rest-api", () => new Rest(useRuntimeConfig().public.apiBase));

      at createNoMappedModuleFoundError (node_modules/jest-resolve/build/resolver.js:759:17)
      at Object.<anonymous> (node_modules/nuxt/dist/app/composables/payload.js:6:1)
      at Object.<anonymous> (node_modules/nuxt/dist/app/composables/index.js:17:1)
      at Object.<anonymous> (node_modules/nuxt/dist/app/index.js:2:1)
      at Object.<anonymous> (composables/states.ts:3:1)
      at Object.<anonymous> (src/domain/services/sanitizer.ts:2:1)
      at Object.<anonymous> (src/domain/services/sanitizer.test.ts:2:1)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.743 s
Ran all test suites.

@da2ce7 da2ce7 added the Needs Rebase Base Branch has Incompatibilities label Jul 17, 2023
@josecelano josecelano linked an issue Jul 26, 2023 that may be closed by this pull request
@josecelano josecelano closed this by deleting the head repository Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Help Wanted More Contributions are Appreciated Needs Rebase Base Branch has Incompatibilities

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Scaffolding for unit testing

2 participants