Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest tester is not working when component have styling files #60

Open
JoshK2 opened this issue Sep 9, 2019 · 6 comments
Open

Jest tester is not working when component have styling files #60

JoshK2 opened this issue Sep 9, 2019 · 6 comments

Comments

@JoshK2
Copy link
Member

JoshK2 commented Sep 9, 2019

I have a project written in react and typescript, and tested with jest tester and is not working.
This is the error I get:

Test suite failed to run 
      ● Test suite failed to run

    /workspace/environment/1117b971-f18d-4fdb-a341-f715b3fb6f08/dist/components/Alert/alert.scss:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){@import '../../styles/variables.scss';
                                                                                             ^
    
    SyntaxError: Invalid or unexpected token

      22 | Object.defineProperty(exports, "__esModule", { value: true });
      23 | var react_1 = __importStar(require("react"));
    > 24 | require("./alert.scss");
      25 | var Alert = /** @class */ (function (_super) {
      26 |     __extends(Alert, _super);
      27 |     function Alert() {
      
      at ScriptTransformer._transformAndBuildScript (../../../../../components/testers/jest/bit.envs/22.4.3/node_modules/jest-runtime/build/script_transformer.js:316:17)
      at Object.<anonymous> (alert.js:24:1)
      at Object.<anonymous> (index.js:3:15)

STR:

  • clone this project https://github.com/JoshK2/create-react-components-library.
  • run this bit add command: bit add src/assets/* -n assests && bit add src/components/*/ -t 'src/components/{PARENT}/*test.tsx' && bit add src/styles/* -n styles && bit add src/utils/*/ -t 'src/utils/{PARENT}/*test.ts'
  • run bit status, should be ok.
  • impor this compiler bit.envs/compilers/[email protected]
  • import the tester bit.envs/testers/[email protected]
  • run bit tag like this if you want to see the error in the cloud: bit tag -a --skip-tests

and this is my jest.config.js:

module.exports = {
    preset: 'ts-jest',
    snapshotSerializers: ['enzyme-to-json/serializer'],
    testEnvironment: 'node',
    transform: {
        '^.+\\.tsx?$': 'ts-jest'
    },
    testRegex: '/src/.*\\.test.(ts|tsx)$',
    moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
    setupFiles: ['<rootDir>/setupTests.ts'],
    collectCoverage: true,
    collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/index.ts', '!**/node_modules/**'],
    moduleNameMapper: {
        '^.+\\.(css|less|scss)$': 'identity-obj-proxy'
    }
};
@JoshK2 JoshK2 changed the title Jest tester is not Jest tester is not working when component have styling files Sep 9, 2019
@CloudPower97
Copy link

I have the same exact problem.
Is this going to be a quick fix or... ? 🙏

@qballer
Copy link
Contributor

qballer commented Sep 11, 2019

Typescript compiler updated to 3.0.28, can you check the issue with that version ?
Please note you can use typescript directly and not the react-typescript version. They are different names leading to the same place.

@CloudPower97
Copy link

@qballer I'm actually using bit.envs/compilers/[email protected] and apart from the problems with jest tester everything is working fine.
However, when switching to bit.envs/compilers/[email protected] the build step is failing as well with the following error:

⠨ building components(node:29667) ExperimentalWarning: The fs.promises API is experimental
⡋⠀ building componentsNavbar/Navbar.tsx:7:19 - error TS2307: Cannot find module './Navbar.module.css'.

7 import Style from './Navbar.module.css';
                    ~~~~~~~~~~~~~~~~~~~~~

Navbar/UserDropdown/index.tsx:7:19 - error TS2307: Cannot find module './UserDropdown.module.css'.

7 import Style from './UserDropdown.module.css';
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 2 errors.

error: bit failed to build claudio_cortese.terram/[email protected] with the following exception:
Command failed with exit code 2 (ENOENT): /home/claudio/Documents/Abstract/terram-components/.bit/components/compilers/typescript/bit.envs/3.0.28/node_modules/typescript/bin/tsc -d
Error: Command failed with exit code 2 (ENOENT): /home/claudio/Documents/Abstract/terram-components/.bit/components/compilers/typescript/bit.envs/3.0.28/node_modules/typescript/bin/tsc -d
    at makeError (/home/claudio/Documents/Abstract/terram-components/.bit/components/compilers/typescript/bit.envs/3.0.28/node_modules/execa/lib/error.js:58:11)
    at handlePromise (/home/claudio/Documents/Abstract/terram-components/.bit/components/compilers/typescript/bit.envs/3.0.28/node_modules/execa/index.js:112:26)
    at process._tickCallback (internal/process/next_tick.js:68:7)

As you can see I'm using CSS Modules.

Thoughts?

@qballer
Copy link
Contributor

qballer commented Sep 22, 2019

Can you share a small repo which reconstructs this issue ?

@CloudPower97
Copy link

@qballer Sure, going to do that ASAP ☺️

@qballer qballer removed their assignment Jun 19, 2020
@FDiskas
Copy link

FDiskas commented Feb 22, 2021

And it's gone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants