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

Group suites over multiple files #1792

Closed
marcojahn opened this issue Jul 7, 2015 · 4 comments
Closed

Group suites over multiple files #1792

marcojahn opened this issue Jul 7, 2015 · 4 comments

Comments

@marcojahn
Copy link

When splitting my tests accross multiple files I got them grouped for each file.

// file1.js
describe('test 1 - file 1', function () {
    // more testcode here
});

// file2.js
describe('test 1 - file 2', function () {
    // more testcode here
});

The output is as expected

test 1 - file 1
    (tests listed here)
test 1 - file 2
    (tests listed here)

But I wonder if it is possible to group these tests by defining an additional "shared" describe

// file1.js
describe('grouped', function () {
    describe('test 1 - file 1', function () {
        // more testcode here
    });
});

// file2.js
describe('grouped', function () {
    describe('test 1 - file 2', function () {
        // more testcode here
    });
});

The expected output would be

grouped
    test 1 - file 1
        (tests listed here)
    test 1 - file 2
        (tests listed here)
@marcojahn
Copy link
Author

This is how I currently achieve the desired output, but I am not sure if it just a workaround or how it should be done.

export default function () {
    describe('test 1 - file 1', function () {
        // more testcode here
    });
}

import Test1 from './test1.js';

describe('grouped', function () {
    Test1();
});

@boneskull
Copy link
Contributor

dupe of #1413

@paulbhartzog
Copy link

paulbhartzog commented Oct 23, 2019

Here's the same solution, but with different syntax:

one.js

function test1 () {
  describe('test 1 - file 1', function () {
    it('should be true', function () {
      expect(true).to.be.true
    })
  })
}
module.exports = {
  test1:test1
}

(do that ^ for each file of tests)

and this to use them in a group:
grouped.js

const one = require('./one.js')
const two = require('./two.js')
describe('grouped', function () {
  one.test1()
  two.test1()
})

Hope that helps

@danon
Copy link

danon commented Oct 24, 2023

This is how I currently achieve the desired output, but I am not sure if it just a workaround or how it should be done.

export default function () {
    describe('test 1 - file 1', function () {
        // more testcode here
    });
}

import Test1 from './test1.js';

describe('grouped', function () {
    Test1();
});
  1. If you do that, you can no longer run this one particular file - you can only run it as a part of the suite.
  2. That's not ideal, since adding new test suits, requires editing the "joiner module", and can cause for example conflicts when merging multiple codes.

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

No branches or pull requests

4 participants