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

[BUG] Extension stops detecting tests after 2 launches #1189

Open
NeilRiver opened this issue Oct 20, 2024 · 3 comments
Open

[BUG] Extension stops detecting tests after 2 launches #1189

NeilRiver opened this issue Oct 20, 2024 · 3 comments
Labels
need sample repo needs a sample repo to further investigate

Comments

@NeilRiver
Copy link

Describe the bug
It's simple, I develop tests, and finally decided to check them, an error occurred, I click on the icon 2 times and on the 3rd time all the icons in the tests disappear.

Screenshots

  1. all ok
    image
  2. one more click and everyone reload the page if you want the icon to appear
    image
  3. and it is not clear why he started to consider import as a test?
    image

Environment (please complete the following information):

  • vscode-jest version: v6.2.5
  • node -v: v20.18.0
  "devDependencies": {
    "@faker-js/faker": "^9.0.3",
    "@types/jest": "^29.5.13",
    "axios": "^1.7.7",
    "faker": "^6.6.6",
    "jest": "^29.7.0",
    "prettier": "3.3.3",
    "ts-jest": "^29.2.5",
    "zod": "^3.23.8"
  }
}
module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  setupFilesAfterEnv: ['./jest.setup.js']
};
{
  "editor.formatOnSave": true,
  "jest.runMode": "on-demand"
}
  • Operating system: Fedora 40

at the moment i run tests by clicking on the icon

@NeilRiver
Copy link
Author

I found out what the matter was, the problem was in my global handler of basic checks.

I really don't like duplicating code, inserting these usual checks and I found a way to check. Question... why does the extension crash from this?

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  setupFilesAfterEnv: ['./jest.setup.js']
};
// ./jest.setup.js
const originalTest = global.test;

global.test = (name, fn, timeout) => {
  return originalTest(
    name,
    async () => {
      const result = await fn();
      if (result && typeof result === 'object' && 'status' in result) {
        const isSuccessStatus = (status) => status >= 200 && status < 300;
        expect(isSuccessStatus(result.status)).toBeTruthy();
        expect(result.duration).toBeLessThan(1000);
        expect(result.headers['content-type']).toMatch(/application\/json/);
        expect(result.headers['connection']).toBe('keep-alive');
        expect(() => JSON.parse(JSON.stringify(result.data))).not.toThrow();
      }
      return result;
    },
    timeout
  );
};

@connectdotz
Copy link
Collaborator

Hmm... It is not clear to me why the global setup will trigger this behavior... Do you have a sample repo that we can try to repro your issue?

@connectdotz connectdotz added the need sample repo needs a sample repo to further investigate label Nov 3, 2024
@NeilRiver
Copy link
Author

NeilRiver commented Nov 4, 2024

Hmm... It is not clear to me why the global setup will trigger this behavior... Do you have a sample repo that we can try to repro your issue?

Sorry, this is a working project
i already abandoned this solution because there is duplication here... i call the async request 2 times... before the test and in the test itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need sample repo needs a sample repo to further investigate
Projects
None yet
Development

No branches or pull requests

2 participants