zaqqaz / jest-allure

Generate Allure Report for jest. Allure Report, a flexible lightweight multi-language test report tool with the possibility to add steps, attachments, parameters and so on.
MIT License
113 stars 38 forks source link

jasmine is not defined error coming up when we try to run script #8

Open vjuturu opened 5 years ago

vjuturu commented 5 years ago

ReferenceError: jasmine is not defined at registerAllureReporter (/Users/xxxx/Projects/xxxx/xxxx/node_modules/jest-allure/dist/setup.js:46:5)

Steps followed:

  1. "jest": { "setupTestFrameworkScriptFile": "./func-test-jest.config.js" },
  2. just imported in global setup file const { registerAllureReporter } = require("jest-allure/dist/setup");

please advise.

Thanks --vj

theasc commented 5 years ago

I have the same problem. Any solution to it?

zaqqaz commented 5 years ago

Don't faced with such error yet. Could you provide more information ? (better link to demo project somewhere on github).

Btw, here is demo project with jest-alure integration https://github.com/zaqqaz/visual-unit-tests/blob/master/src/setupTests.ts

just clone it and try it yourself.

akaguny commented 5 years ago

Show your version of jest @vjuturu. And try to add something as setupFilesAfterEnv: ["jest-allure/dist/setup"] in your jest.config.js; Now i will check compatibility jest-allure with the latest jest and will try to get PR because i think that jest-allure not up to date

akaguny commented 5 years ago

resolved in #15

kevinoliveira commented 5 years ago

Versions "jest": "^24.8.0", "jest-allure": "^0.1.1",

jest.config.js

module.exports = {
    reporters: ["default", "jest-allure","jest-stare"],
    setupFilesAfterEnv: ["jest-allure/dist/setup"]
};
FAIL  src/home/example.test.ts
  ● Test suite failed to run

    Your test suite must contain at least one test.

      at node_modules/@jest/core/build/TestScheduler.js:242:24
      at asyncGeneratorStep (node_modules/@jest/core/build/TestScheduler.js:131:24)
      at _next (node_modules/@jest/core/build/TestScheduler.js:151:9)
      at node_modules/@jest/core/build/TestScheduler.js:156:7
      at node_modules/@jest/core/build/TestScheduler.js:148:12
      at onResult (node_modules/@jest/core/build/TestScheduler.js:271:25)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.329s
Ran all test suites.

I have tests, those are the results if i remove setupFilesAfterEnv from jest config file

 PASS  src/home/example.test.ts
  ✓ example testing (3ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.354s
Ran all test suites.
zaqqaz commented 5 years ago

@kevinoliveira can you attach the source of src/home/example.test.ts?

kevinoliveira commented 5 years ago

src/home/example.ts

const example = ()=>"this is a example!";

export {example}

src/home/example.test.ts

import { example} from "./example";

test(
"example testing",
() => expect(example()).toBe("this is a example!")
);
cinderblock commented 4 years ago

I am also getting error:

  ● Test suite failed to run

    ReferenceError: jasmine is not defined

      at registerAllureReporter (node_modules/jest-allure/dist/setup.js:46:5)
      at Object.<anonymous> (node_modules/jest-allure/dist/setup.js:49:1)
          at Array.forEach (<anonymous>)

jest.config.js

  ...
  setupFilesAfterEnv: ['jest-allure/dist/setup'],
  reporters: [
    'default',
    'jest-github-reporter',
    ...

package.json

  ...
  "devDependencies": {
    "jasmine": "^3.5.0",
    "jest-allure": "^0.1.1",
    ...
  }

tests/main.ts

import { wait } from '../src/wait';
import process from 'process';
import cp from 'child_process';
import path from 'path';

test('throws invalid number', async () => {
  const input = parseInt('foo', 10);
  await expect(wait(input)).rejects.toThrow('milliseconds not a number');
});

test('wait 500 ms', async () => {
  const start = new Date();
  await wait(500);
  const end = new Date();
  const delta = Math.abs(end.getTime() - start.getTime());
  expect(delta).toBeGreaterThan(450);
});

// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
  process.env['INPUT_MILLISECONDS'] = '500';
  const ip = path.join(__dirname, '..', 'lib', 'main.js');
  const options: cp.ExecSyncOptions = {
    env: process.env,
  };
  console.log(cp.execSync(`node ${ip}`, options).toString());
});

EDIT:

Looks like it's because of testRunner: 'jest-circus/runner'


EDIT2:

@kevinoliveira Looks like I'm actually having the same problem (which is I think different that this one) over in #43.

SandyLQ commented 4 years ago

@kevinoliveira Hello, I have the same issue as you had, I am curious if you solved it? I am using jest 25.1.0

YuriiSmal commented 4 years ago

@kevinoliveira Hello, I have the same issue as you had, I am curious if you solved it?

Hi, I had the same situation and found no one answer wich worked for me. Now I using another way. I added this row for jest.config.js testRunner : 'jasmine2'

it's resolve issue with ReferenceError: jasmine is not defined at registerAllureReporter

and report generate successed

kevinoliveira commented 4 years ago

Awesome news, I will take a look on the next few days!

zaqqaz commented 3 years ago

Yep, that's the correct solution. https://github.com/zaqqaz/jest-allure#uses-jest-circus-or-jest--v-27-

character123 commented 3 years ago

@kevinoliveira Hello, I have the same issue as you had, I am curious if you solved it?

Hi, I had the same situation and found no one answer wich worked for me. Now I using another way. I added this row for jest.config.js testRunner : 'jasmine2'

it's resolve issue with ReferenceError: jasmine is not defined at registerAllureReporter

and report generate successed

Thanks! It works for me

jbricenoz commented 3 years ago

Hi! I was able to fix the issue using:

testRunner : 'jasmine2',

into the jest config file:

module.exports = {
    verbose: true,
    preset: 'jest-playwright-preset',
    testRunner : 'jasmine2',
    transform:{
        "^.+\\.tsx?$": "ts-jest",
    },
    testTimeout: 120000,
    reporters: ["default", "jest-allure"],
    moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
    setupFilesAfterEnv: ['jest-allure/dist/setup','expect-playwright'],
    testMatch: [
        "**/tests/**/*.spec.(js|jsx|ts|tsx)",
        // "**/tests/**/*.test.(js|jsx|ts|tsx)"
    ]
};
pedronastasi commented 2 years ago

I'm using Jest 27 and testRunner : 'jasmine2' didn't work for me

Instead I added this to my package.json and worked:

 "jest": {
    "testRunner": "jest-jasmine2"
  }
saritvakrat commented 1 year ago

I have Jest 29, adding, I tried several solutions, still does not work

hoa-pham82 commented 1 year ago

I have Jest 29, adding, I tried several solutions, still does not work

@saritvakrat Try to install this package: jest-jasmine2 and set it to the file jest.config.js: testRunner: "jest-jasmine2"