• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sudo-suhas / elastic-builder / 19727954794

27 Nov 2025 07:02AM UTC coverage: 99.961% (-0.04%) from 100.0%
19727954794

push

github

web-flow
test: migrate from AVA to Vitest and remove test macros (#221)

Replace AVA test framework with Vitest and eliminate all test macros
by expanding them into explicit, self-documenting test cases. This
migration improves developer experience with watch mode, built-in
coverage reporting, and makes each test independently readable.

Key changes:

Dependencies and Configuration:
- Replace AVA with Vitest for test execution
- Remove NYC in favor of Vitest's built-in coverage (@vitest/coverage-v8)
- Remove eslint-plugin-ava and add eslint-plugin-vitest
- Create vitest.config.js with ES Modules support, parallel execution,
  and coverage configuration matching previous NYC settings
- Configure coverage to generate html, lcov, and text reports in a
  single test run

Test Migration (153 test files transformed):
- Convert all test files from AVA syntax to Vitest syntax
- Replace AVA's `t.deepEqual()` with `expect().toEqual()`
- Replace AVA's `t.truthy()` with `expect().toBeTruthy()`
- Replace AVA's `t.throws()` with `expect().toThrow()`
- Use explicit imports: `import { test, expect, describe } from 'vitest'`

Test Macro Elimination:
- Remove test/_macros.js entirely (contained 6 test macro patterns)
- Expand `setsAggType` macro into explicit aggregation type tests
- Expand `validatedCorrectly` macro into table-driven validation tests
- Expand `makeSetsOptionMacro` generated tests into explicit option tests
- Expand `illegalCall` macro into explicit error tests with toThrow()
- Expand `illegalParamType` macro into explicit TypeError tests
- All expanded tests follow table-driven patterns for maintainability

Test Utilities:
- Create test/testutil/ package for shared test helper functions
- Add type checking utilities for parameter validation
- Export all utilities from test/testutil/index.js
- Reuse existing recursiveToJSON from src/core/util.js

Package Scripts:
- Update test:src: `vitest run --coverage` (single-step execution)
- Remove report script (now redu... (continued)

1367 of 1370 branches covered (99.78%)

Branch coverage included in aggregate %.

19247 of 19252 relevant lines covered (99.97%)

10.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.52
/src/core/runtime-field.js
1
'use strict';
3✔
2

3✔
3
const _ = require('../_');
3✔
4
const validType = [
3✔
5
    'boolean',
3✔
6
    'composite',
3✔
7
    'date',
3✔
8
    'double',
3✔
9
    'geo_point',
3✔
10
    'ip',
3✔
11
    'keyword',
3✔
12
    'long',
3✔
13
    'lookup'
3✔
14
];
3✔
15

3✔
16
/**
3✔
17
 * Class supporting the Elasticsearch runtime field.
3✔
18
 *
3✔
19
 * [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html)
3✔
20
 *
3✔
21
 * Added in Elasticsearch v7.11.0
3✔
22
 * [Release note](https://www.elastic.co/guide/en/elasticsearch/reference/7.11/release-notes-7.11.0.html)
3✔
23
 *
3✔
24
 * @param {string=} type One of `boolean`, `composite`, `date`, `double`, `geo_point`, `ip`, `keyword`, `long`, `lookup`.
3✔
25
 * @param {string=} script Source of the script.
3✔
26
 *
3✔
27
 * @example
3✔
28
 * const field = esb.runtimeField('keyword', `emit(doc['sessionId'].value + '::' + doc['name'].value)`);
12✔
29
 */
12✔
30
class RuntimeField {
12✔
31
    // eslint-disable-next-line require-jsdoc
12✔
32
    constructor(type, script) {
12✔
33
        this._body = {};
78✔
34
        this._isTypeSet = false;
78✔
35
        this._isScriptSet = false;
78✔
36

78✔
37
        if (!_.isNil(type)) {
78✔
38
            this.type(type);
75✔
39
        }
75✔
40

78✔
41
        if (!_.isNil(script)) {
78✔
42
            this.script(script);
63✔
43
        }
12✔
44
    }
12✔
45

12✔
46
    /**
12✔
47
     * Sets the source of the script.
12✔
48
     * @param {string} script
12✔
49
     * @returns {RuntimeField} returns `this` so that calls can be chained.
3✔
50
     */
3✔
51
    script(script) {
3✔
52
        this._body.script = {
69✔
53
            source: script
69✔
54
        };
69✔
55
        this._isScriptSet = true;
69✔
56
        return this;
69✔
57
    }
69✔
58

3✔
59
    /**
3✔
60
     * Sets the type of the runtime field.
3✔
61
     * @param {string} type One of `boolean`, `composite`, `date`, `double`, `geo_point`, `ip`, `keyword`, `long`, `lookup`.
3✔
62
     * @returns {RuntimeField} returns `this` so that calls can be chained.
12!
63
     */
×
64
    type(type) {
12✔
65
        const typeLower = type.toLowerCase();
135✔
66
        if (!validType.includes(typeLower)) {
135✔
67
            throw new Error(`\`type\` must be one of ${validType.join(', ')}`);
3✔
68
        }
3✔
69
        this._body.type = typeLower;
129✔
70
        this._isTypeSet = true;
129✔
71
        return this;
129✔
72
    }
135✔
73

3✔
74
    /**
3✔
75
     * Specifies the language the script is written in. Defaults to `painless` but
3✔
76
     * may be set to any of languages listed in [Scripting](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html).
3✔
77
     *
3✔
78
     * @param {string} lang The language for the script.
3✔
79
     * @returns {RuntimeField} returns `this` so that calls can be chained.
3✔
80
     */
3✔
81
    lang(lang) {
3✔
82
        if (!_.isNil(this._body.script)) {
6✔
83
            this._body.script.lang = lang;
3✔
84
        }
3✔
85
        return this;
6✔
86
    }
6✔
87

3✔
88
    /**
3✔
89
     * Specifies any named parameters that are passed into the script as variables.
3✔
90
     *
3✔
91
     * @param {Object} params Named parameters to be passed to script.
3✔
92
     * @returns {RuntimeField} returns `this` so that calls can be chained.
3✔
93
     */
3✔
94
    params(params) {
3✔
95
        if (!_.isNil(this._body.script)) {
6✔
96
            this._body.script.params = params;
3✔
97
        }
3✔
98
        return this;
6✔
99
    }
6✔
100

3✔
101
    /**
3✔
102
     * Override default `toJSON` to return DSL representation for the `script`.
3!
103
     *
×
104
     * @override
×
105
     * @returns {Object} returns an Object which maps to the elasticsearch query DSL
12!
106
     */
×
107
    toJSON() {
✔
108
        if (!this._isTypeSet) {
18✔
109
            throw new Error('`type` should be set');
3✔
110
        }
3✔
111

15✔
112
        if (!this._isScriptSet) {
18✔
113
            throw new Error('`script` should be set');
6✔
114
        }
6✔
115

9✔
116
        return this._body;
9✔
117
    }
18✔
118
}
3✔
119

3✔
120
module.exports = RuntimeField;
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc