question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to run tests if test files are not inside src directory using Snowpack

See original GitHub issue
tests/App.test.jsx:

 🚧 Browser logs:
      TypeError: Failed to fetch dynamically imported module: http://localhost:8000/easy-collab-frontend/tests/App.test.jsx?wtr-session-id=b3ca1529-8150-4d2c-b050-5a62560ca4c0

When I put my whole tests folder inside the src directory everything seems to work but if I put it in root it starts giving the error.

// App.test.jsx

import React from 'react';
import { render, screen } from '@testing-library/react';
import { expect } from 'chai';

import '../src/internationalization/index';
import App from '../src/components/App';

describe('App', () => {
  it('renders App component', () => {
    render(<App />);
    const unauth = screen.getByText('Unauthorized Access!!');
    expect(document.body.contains(unauth));
  });
});
//  web-test-runner.config.js

process.env.NODE_ENV = 'test';
const str = require('@snowpack/web-test-runner-plugin')();

module.exports = {
  testFramework: {
    config: {
      ui: 'bdd',
      timeout: '2000',
    },
  },
  plugins: [str],
  coverageConfig: {
    exclude: ['**/*/_snowpack/**/*'],
  },
};

Script

    "test": "web-test-runner \"tests/**/*.test.jsx\" --node-resolve",

If someone can help, it would be great or if it’s a bug then please provide some workarounds.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
IanVScommented, May 25, 2021

@ShivamJoker here’s an example with most of the rest of the config stripped out:

const IS_TESTING = process.env.NODE_ENV === 'test';

const mount = {
  public: { url: '/', static: true },
  src: { url: '/dist' },
};

if (IS_TESTING) {
  mount['test-setup'] = { url: '/test-setup' };
}

module.exports = {
  mount,
  plugins: [],
  routes: [],
  optimize: {},
  packageOptions: {
    polyfillNode: IS_TESTING,
  },
  devOptions: {},
  buildOptions: {},
};

In my case, I put my actual test files next to my components in /src, but I have some setup files that I only want to mount when I’m testing. You could do something similar for your /tests directory.

0reactions
IanVScommented, May 25, 2021

@ShivamJoker what would you suggest should be implemented?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: @snowpack/web-test-runner coverage #2157 - GitHub
I mount /src to / ) then any code coverage report generated by web test runner is broken because it fails to locate...
Read more >
snowpack.config.js
"test" : testOptions.files are not excluded, and will be scanned & built as normal source files. Useful when running tests on top of...
Read more >
Snowpack 3.8 cannot find the source folder, running dev ...
I would like my index.html file to be in the src directory, but then snowpack does not find the index.html file. When starting...
Read more >
Parcel
Parcel automatically tracks all of the files, configuration, plugins, and dev dependencies that are involved in your build, and granularly invalidates the cache ......
Read more >
Jest 27: New Defaults for Jest, 2021 edition
In the Jest 26 blog post about a year ago, we announced that after two ... of defaults and other notable breaking changes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found