Global

Members


$ :Steps

Steps collection.

Type:
Source:
See:
  • steps to get more details about its methods.

allure

Allure helper.

Source:

CONF

GlaceJS config.

Source:
See:
  • config to get more details about its options.

reporters :Array.<object>

Registered reporters.

Type:
  • Array.<object>
Source:

sinon

SinonJS is pretty nice lib for mocking.

Source:

stubObject

Stubs object with its properties recursively.

Source:

Methods


after(func)

Global function, existing in glace tests, which create after hook.

after hook executes after all chunks in test or all tests in scope / suite / session.

Parameters:
Name Type Description
func function

Hook function. Can be async too.

Source:
Examples

after chunks

test("my test", () => {

    after(() => {
        doSomeThing();
    });

    chunk("first chunk", () => {
        doSomeThingAgain();
    });

    chunk("second chunk", () => {
        andDoSomeThingAgain();
    });
});

after tests

suite("my suite", () => {

    after(async () => {
        await db.connect();
    });

    test("first", () => {
        chunk(async () => {
            await db.query("select * from users");
        });
    });

    test("second", () => {
        chunk(async () => {
            await db.query("select * from products");
        });
    });
});

afterChunk(func)

Global function, existing in glace tests, which creates afterChunk hook.

afterChunk hook executes after each chunk in test.

Parameters:
Name Type Description
func function

Hook function.

Source:
Example
test("Some test", () => {

    afterChunk(() => {
        someFunc();
    });

    chunk("Chunk #1", () => {
        someFunc();
    });

    chunk("Chunk #2", () => {
        someFunc();
    });
});

before(func)

Global function, existing in glace tests, which create before hook.

before hook executes before all chunks in test or all tests in scope / suite / session.

Parameters:
Name Type Description
func function

Hook function. Can be async too.

Source:
Examples

before chunks

test("my test", () => {

    before(() => {
        doSomeThing();
    });

    chunk("first chunk", () => {
        doSomeThingAgain();
    });

    chunk("second chunk", () => {
        andDoSomeThingAgain();
    });
});

before tests

suite("my suite", () => {

    before(async () => {
        await db.connect();
    });

    test("first", () => {
        chunk(async () => {
            await db.query("select * from users");
        });
    });

    test("second", () => {
        chunk(async () => {
            await db.query("select * from products");
        });
    });
});

beforeChunk(func)

Global function, existing in glace tests, which creates beforeChunk hook.

beforeChunk hook executes before each chunk in test.

Parameters:
Name Type Description
func function

Hook function.

Source:
Example
test("Some test", () => {

    beforeChunk(() => {
        someFunc();
    });

    chunk("Chunk #1", () => {
        someFunc();
    });

    chunk("Chunk #2", () => {
        someFunc();
    });
});

chunk( [name] [, opts], func)

Global function, existing in glace tests, which creates test chunk.

chunk is independently executed part of test. It means that even if first chunk is failed, other will be executed in any case. test should contain as minimum one chunk.

Parameters:
Name Type Argument Default Description
name string <optional>
null

Name of chunk.

opts object <optional>

Chunk options.

Properties
Name Type Argument Default Description
retry number <optional>
<nullable>
null

Number of chunk retries on failure. Overrides config and test settings.

timeout number <optional>
<nullable>
null

Time limit to execute chunk, sec. Overrides config and test settings.

func function

Callback function with test payload. Can be async too.

Source:
Examples

Anonymous chunk

test("My test", () => {
    chunk(() => {
        var a = 5;
        expect(a).to.be.equal(2);
    });
});

Named chunk

test("My test", () => {
    chunk("My chunk", () => {
        var a = 5;
        expect(a).to.be.equal(2);
    });
});

Chunk with options

test("My test", () => {
    chunk("My chunk", { retry: 2, timeout: 1 }, () => {
        var a = 5;
        expect(a).to.be.equal(2);
    });
});

Several chunks in test

test("My test", () => {
    chunk("first chunk", () => {
        expect(2).to.be.equal(3);
    });
    chunk("second chunk", () => {
        expect(3).to.be.equal(3);
    });
});

Async chunk

test("My test", () => {
    chunk(async () => {
        await Promise.resolve("done!");
    });
});

expect(actualValue)

chaijs expect function.

Parameters:
Name Type Description
actualValue *

Some actual value which should be checked.

Source:
See:
  • chaijs to get more details about `expect` usage.
Example
expect(1).to.be.equal(1);
expect(2).to.be.gte(0);

forEachLanguage( [name] [, fixtures] [, opts], func)

Iterates test chunks through all languages specified in config or options.

It's applicable for multilingual application. If list of languages is specified, it will be used firstly. Otherwise from configuration.

Parameters:
Name Type Argument Default Description
name object <optional>
"for language"

Iterator namespace (will be report).

fixtures Array.<function()> <optional>

Involved fixtures list.

opts object <optional>

Options.

Properties
Name Type Argument Default Description
languages Array.<string> <optional>
<nullable>

List of tested languages.

chunkRetry number <optional>
0

Number of chunk retries on failure. Overrides config value for concrete test chunks.

chunkTimeout number <optional>
<nullable>
null

Time to execute chunk or hook, sec.

func function

Function with test steps.

Source:
Example
test("Some test", ctx => {
    forEachLanguage(lang => {
        chunk(() => {
            // payload
        });
    });
});

glaceRun(cb)

Runs glace framework.

Parameters:
Name Type Description
cb function

Callback.

Source:

help(d, cb)

Help description.

Parameters:
Name Type Description
d function

Function to process option description.

cb function

Callback to expand default help.

Source:

run(cb)

Runs tests.

  • executes runner.js file, which is entry point to load and execute files with tests
  • connects custom reporter to mochajs.
Parameters:
Name Type Description
cb function

Callback.

Source:

scope(name [, fixtures] [, opts], func)

Execute tests scope.

Parameters:
Name Type Argument Description
name string

Scope name.

fixtures Array.<function()> <optional>

List of fixtures.

opts object <optional>

Scope options.

Properties
Name Type Argument Description
chunkRetry number <optional>

Number of chunk retries on failure.

chunkTimeout number <optional>

Time to execute chunk or hook, sec.

func function

Callback function with test cases.

Source:
Example
scope("Some test scope", () => {
    test("Some test name", () => {
        before(() => {
            someFunc();
        });
        chunk("chunk #1", () => {
            someFunc();
        });
        chunk("chunk #2", () => {
            someFunc();
        });
    });
});

session( [name] [, fixtures], func)

Executes tests session.

Parameters:
Name Type Argument Default Description
name string <optional>

Session name. By default it includes start date time.

fixtures object <optional>
[]

Session fixtures.

func function

Function with test cases.

Source:
Example
session(() => {
    test("Test #1", () => {
        chunk("Chunk #1", () => {
            someFunc();
        });
        chunk("Chunk #2", () => {
            someFunc();
        });
    });
    test("Test #2", () => {
        chunk("Chunk #1", () => {
            someFunc();
        });
        chunk("Chunk #2", () => {
            someFunc();
        });
    });
});

suite(name [, fixtures] [, opts], func)

Creates tests suite.

Parameters:
Name Type Argument Description
name string

Suite name.

fixtures Array.<function()> <optional>

List of fixtures.

opts object <optional>

Suite options.

Properties
Name Type Argument Description
chunkRetry number <optional>

Number of chunk retries on failure.

chunkTimeout number <optional>

Time to execute chunk or hook, sec.

func function

Callback function with test cases.

Source:
Example
suite("Some test suite", () => {
    test("Some test name", () => {
        before(() => {
            someFunc();
        });
        chunk("chunk #1", () => {
            someFunc();
        });
        chunk("chunk #2", () => {
            someFunc();
        });
    });
});

test(name [, opts] [, fixtures], func)

Global function, existing in glace tests, which creates test case.

Parameters:
Name Type Argument Description
name string

Name of test case. By default, should be unique in session. But uniqueness check can be skipped with CLI option --dont-check-names.

opts object <optional>

Options.

Properties
Name Type Argument Default Description
skip boolean | string <optional>
false

Flag to skip test or skip reason message.

retry number <optional>
<nullable>
null

Number of test retries on failure. Overrides config settings.

chunkRetry number <optional>
<nullable>
null

# Number of chunk retries on failure. Overrides config settings.

chunkTimeout number <optional>
<nullable>
null

# Time to execute chunk or hook, sec. Overrides config settings.

fixtures Array.<function()> <optional>

Involved fixtures list.

func function

Сallback function with chunks and hooks.

Source:
Examples

Simple test

test("Some test", () => {
    chunk("Some chunk", () => {
        someFunc();
    });
});

Test with retry

test("Test with retry", { retry: 2 }, () => {
    chunk(() => {
        someFunc();
    });
});

Test with fixtures

test("Test with fixtures", null, [fix_func_1, fix_func_2], () => {
    chunk(() => {
        someFunc();
    });
});