mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-05 16:10:43 +00:00
### **User description** added unit test cases for missing files ___ ### **PR Type** Tests, Enhancement ___ ### **Description** - Add extensive unit tests coverage - Expose internals for testability - Improve VRL language modularity - Export utility for reuse in tests ___ ### Diagram Walkthrough ```mermaid flowchart LR specs["Add comprehensive spec files"] -- drive coverage --> composables["Composable internals exposed for tests"] composables -- supports --> store["Store mocks and helpers updated"] language["VRL language keywords exported"] -- reuse in tests --> specs billing["Export formatDate utility"] -- reuse in tests --> specs ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Tests</strong></td><td><details><summary>4 files</summary><table> <tr> <td><strong>SearchBar.spec.ts</strong><dd><code>Add 145+ tests for SearchBar methods</code> </dd></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-63ac75d3fe278dad233e7dd7c51b3b33076d54a776b89ae05190d8522130c78b">+2196/-0</a></td> </tr> <tr> <td><strong>useStreams.spec.ts</strong><dd><code>Rewrite and expand useStreams unit tests</code> </dd></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-513e2d53c46c553904a054e9c2cd12d33e800afc54fe5b4192c9782382ecd79b">+727/-175</a></td> </tr> <tr> <td><strong>useStreams.ts</strong><dd><code>Expose internal helpers for testing</code> </dd></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-a083369344f022cdf8d4f536719179b1d920369e33e2e26234e70dd36d151a7c">+11/-1</a> </td> </tr> <tr> <td><strong>store.ts</strong><dd><code>Add meta_org to default store state</code> </dd></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-0f8dff694a1fcfaa42d432168e435b7a2aa122d075fedfd6e75e532aca3b2a73">+1/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Enhancement</strong></td><td><details><summary>2 files</summary><table> <tr> <td><strong>vrlLanguage.ts</strong><dd><code>Export VRL keywords and refactor usage</code> </dd></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-d8baadeb1ccdabd0e424d3f335476417990ae5f680645db52ba03a94b75afd7a">+7/-4</a> </td> </tr> <tr> <td><strong>convertBillingData.ts</strong><dd><code>Export formatDate for external use</code> </dd></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-56fa0a54f04a4fd9d5a715f5dbfe80ebcb852a39720160399e427021f75185ec">+1/-1</a> </td> </tr> </table></details></td></tr><tr><td><strong>Additional files</strong></td><td><details><summary>41 files</summary><table> <tr> <td><strong>AddOpenobserveType.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-d4c9e84859e41b57861e8ec93d08f28111c13c5ca1143c0613f9e3f55051a2f2">+365/-11</a></td> </tr> <tr> <td><strong>FolderList.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-0c62fad007c4194fb43b3986b2cbdfb7f6317e8e1e4e402d78ec44c951e7973b">+941/-0</a> </td> </tr> <tr> <td><strong>AppOrganizations.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-0be0b81d3cd8b7003dc2aaf283fbe3f2434963086540a4d6bf1dd513fe9ed19f">+1021/-0</a></td> </tr> <tr> <td><strong>User.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-52945c253c25b4961ba3c66891234a74aa62c69e70f70ee67388bb406f0847cd">+779/-0</a> </td> </tr> <tr> <td><strong>User.vue</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-e973c2a665f9b27b94673ba64cc5b23650300836a727a2e07673c8e26305aee5">+10/-3</a> </td> </tr> <tr> <td><strong>LogstashDatasource.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-2cd019295a25886a037e6ede5cad795b52851a377f48beb46f3897bc6d64a20b">+425/-2</a> </td> </tr> <tr> <td><strong>Login.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-746b43968d685362866c3f97bf2b5e0846bac7463fe1ecb080c1c7d962cb855b">+229/-1</a> </td> </tr> <tr> <td><strong>AssociatedRegexPatterns.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-4ca41bf14fd6a3c79a3877324a7c7520a25d1d33f97fe947b2f6dd4bbf6ca5b4">+310/-0</a> </td> </tr> <tr> <td><strong>AssociatedRegexPatterns.vue</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-c6fce5e1c83798991b6ff19effb23c67af59f38fac0b9e56dcab7a09d139f550">+1/-0</a> </td> </tr> <tr> <td><strong>Nodes.vue</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-65fde080f2ef775dab71d503b730bf029d13640ac241ded1dc22a72185a12082">+1/-0</a> </td> </tr> <tr> <td><strong>OrganizationManagement.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-bff2884ebe60873c476c6a826739f210aca57e39cd503ca0026e48388be48697">+1090/-0</a></td> </tr> <tr> <td><strong>OrganizationManagement.vue</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-21e2431538cb6b76e5ef5b367c6df8fc02ad8f6c1294f438be9937c7481ea9ff">+3/-0</a> </td> </tr> <tr> <td><strong>OrganizationSettings.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-03458cff72df35e454f83d964d2505e87b9c37e4488333e0d18a7757f2b1ebe4">+777/-0</a> </td> </tr> <tr> <td><strong>useEnterpriseRoutes.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-ce0d8e19a397a63cfe5a423399b9c8f8f08eb0e30913ba9b885a00f5703d2ede">+784/-0</a> </td> </tr> <tr> <td><strong>useIngestionRoutes.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-3b7ebacf9481f4643a2b56ffe53ab161fc89d416e280d45b48568866a4dee40c">+1013/-0</a></td> </tr> <tr> <td><strong>useManagementRoutes.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-28a4eb5ed72bef3db05dca1f8e45eef0836819fe0c747783b22cce966d7d6ad4">+608/-0</a> </td> </tr> <tr> <td><strong>useAiChat.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-666a3e460b35ed780ab299fb01537fe3afdb12dabe2b363d5d91a08a728903f9">+614/-0</a> </td> </tr> <tr> <td><strong>useAiChat.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-830ee4f21bdbbd0fa5c5c0f43b0a1d0200831e07ccddc91982cf0371c801b046">+3/-0</a> </td> </tr> <tr> <td><strong>MainLayout.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-59def4c2a6d83249918d30d825ccfb0aa4ce9616586fe13f16a7e29b3827cdbc">+495/-22</a></td> </tr> <tr> <td><strong>MainLayout.vue</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-91e4134141264c4624d4eb4cfa987b33ed31eb6f551e089c0b26f2610dd54362">+6/-1</a> </td> </tr> <tr> <td><strong>MetricLegends.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-87f5d1b4980d975625d85d549607833927202ebffe226643723bc733c344622f">+575/-0</a> </td> </tr> <tr> <td><strong>MetricList.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-cfe67d5bd5005164060b2b219a86074a5b6330e1759260803e54e89255aeb86a">+976/-0</a> </td> </tr> <tr> <td><strong>MetricList.vue</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-bba38d43b27f28395343746a2de5411a2b18ab093d1843ad6bd413ba50a2b236">+5/-0</a> </td> </tr> <tr> <td><strong>SyntaxGuideMetrics.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-e83d30b644b4e25b1867e748793726b149a5f8e5e94aac273d32b9fa9f9d73a6">+505/-0</a> </td> </tr> <tr> <td><strong>HomeView.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-73e32dfbcdec6f87abe68984231fb1227502397e28fd1d91cd9579024010fb82">+771/-0</a> </td> </tr> <tr> <td><strong>Nodes.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-bc3ed81e6399bf6502b432ec0935da08fd0a824adb265a4f579002b4bca13474">+688/-0</a> </td> </tr> <tr> <td><strong>convertBillingData.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-07358b9d1c1df7af083b9843924628f0525bb2c2552ee5e1392b461a99cec321">+492/-0</a> </td> </tr> <tr> <td><strong>convertLogData.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-39de9d9ab51415a842d8aa8cee7fa1beb7234eaed7dfcb996a579a2ef4930b4c">+516/-0</a> </td> </tr> <tr> <td><strong>convertLogData.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-92a6bf770bda75f5e07d57d6cc472f8defa9db6abf02e58de542988b311fed55">+1/-1</a> </td> </tr> <tr> <td><strong>promQLUtils.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-801511331f719d887e0c2df01bfe47bee812895fb67fde768f3b33ba48ace614">+577/-0</a> </td> </tr> <tr> <td><strong>sqlUtils.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-f22df136a6cdfbacf2b637d4902002337620c8e981dbacfdd705455ff899f12d">+2074/-15</a></td> </tr> <tr> <td><strong>sqlUtils.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-dde40e8fcb5c37b06c011ede08922c44a3c025682fbc341aee97ba046b73a0e3">+4/-1</a> </td> </tr> <tr> <td><strong>vrlLanguage.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-8b8d40ee6bba3647f6e5964e1011778519325e45dbde2cf9abc64e3f9308d3e8">+866/-0</a> </td> </tr> <tr> <td><strong>vrlLanguageDefinition.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-7885cf603efcffce2a031eaab866f260d0f699f1a52b961ecd77f0bf8aa72039">+651/-0</a> </td> </tr> <tr> <td><strong>AppAlerts.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-7ac6d93d3aa4a91d52bd751822e423a21158e09bfe70cf96fba46f42376d2acf">+798/-27</a></td> </tr> <tr> <td><strong>Ingestion.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-81be229daf4204aaa0133a1c4cab618bbac68ab704b74ecf3e121636f16c6e61">+1026/-0</a></td> </tr> <tr> <td><strong>Ingestion.vue</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-97b8e8ed2a1260a39442563c7447d4f6d4830a37d47258920d6f94a292cd2d77">+68/-64</a> </td> </tr> <tr> <td><strong>Login.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-92c3c0344a73a30eadb1c98f849f7297c460f50804cdbb2d34dd374fbcf83d74">+1183/-0</a></td> </tr> <tr> <td><strong>ShortUrl.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-3838b4efef178fdab0ba9652f21468b36918b3ca9b84783c564cde2a6556ed39">+326/-29</a></td> </tr> <tr> <td><strong>ShortUrl.vue</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-b7ffcc5de24f9e1db5a3a8e78a686727360f9061ca6f9f8ae60456c3d603f9b7">+7/-0</a> </td> </tr> <tr> <td><strong>User.spec.ts</strong></td> <td><a href="https://github.com/openobserve/openobserve/pull/8151/files#diff-1c14af61b2a316a418e1c7b79ff459ea61e1d1ac1f57b7c768421aa8cdd58cd1">+528/-113</a></td> </tr> </table></details></td></tr></tr></tbody></table> </details> ___
150 lines
5.8 KiB
TypeScript
150 lines
5.8 KiB
TypeScript
import { LanguageSupport, StreamLanguage } from '@codemirror/language'
|
|
import { HighlightStyle, syntaxHighlighting } from '@codemirror/language'
|
|
import { tags as t } from '@lezer/highlight'
|
|
|
|
// VRL keywords for testing and language definition
|
|
export const vrlKeywords = [
|
|
"if", "else", "for", "while", "loop", "break", "continue", "return",
|
|
"let", "in", "as", "use", "impl", "type", "abort", "until", "then", "self", "std"
|
|
];
|
|
|
|
// VRL language definition using StreamLanguage
|
|
export const vrlLanguage = StreamLanguage.define({
|
|
name: 'vrl',
|
|
|
|
token(stream, state) {
|
|
// Comments
|
|
if (stream.match(/###[\s\S]*?###/)) return 'comment'
|
|
if (stream.match(/#[^\n]*/)) return 'comment'
|
|
|
|
// Strings
|
|
if (stream.match(/r'[^']*'/)) return 'regexp'
|
|
if (stream.match(/r"[^"]*"/)) return 'regexp'
|
|
if (stream.match(/s'[^']*'/)) return 'string'
|
|
if (stream.match(/s"[^"]*"/)) return 'string'
|
|
if (stream.match(/t'[^']*'/)) return 'string'
|
|
if (stream.match(/t"[^"]*"/)) return 'string'
|
|
if (stream.match(/'[^']*'/)) return 'string'
|
|
if (stream.match(/"[^"]*"/)) return 'string'
|
|
|
|
// Regular expressions
|
|
if (stream.match(/\/\/\/[^\/]*\/\/\/[igm]*/)) return 'regexp'
|
|
if (stream.match(/\/[^\/]*\/[igm]*/)) return 'regexp'
|
|
|
|
// Numbers
|
|
if (stream.match(/0x[0-9a-fA-F]+/)) return 'number'
|
|
if (stream.match(/0o[0-7]+/)) return 'number'
|
|
if (stream.match(/\d+\.\d+([eE][+-]?\d+)?/)) return 'number'
|
|
if (stream.match(/\d+[eE][+-]?\d+/)) return 'number'
|
|
if (stream.match(/\d+/)) return 'number'
|
|
|
|
|
|
// Booleans
|
|
if (stream.match(/\b(true|false)\b/)) return 'bool'
|
|
|
|
// Null
|
|
if (stream.match(/\bnull\b/)) return 'null'
|
|
|
|
// Keywords
|
|
// if (stream.match(/(?<![a-zA-Z0-9_])(if|else|for|while|loop|break|continue|return|let|in|as|use|impl|type|abort|until|then|self|std)(?![a-zA-Z0-9_])/)) return 'keyword'
|
|
// List of keywords
|
|
const keywords = vrlKeywords;
|
|
|
|
// In your tokenizer:
|
|
if (stream.match(/[a-zA-Z_][\w]*/)) {
|
|
const word = stream.current();
|
|
if (keywords.includes(word)) return 'keyword';
|
|
// ... (function check, etc.)
|
|
return 'variableName';
|
|
}
|
|
|
|
// Literals
|
|
if (stream.match(/\b(true|false|null)\b/)) return 'literal'
|
|
|
|
// Special identifiers
|
|
if (stream.match(/@[a-zA-Z_]\w*/)) return 'variableName'
|
|
|
|
// Function calls (fallible)
|
|
if (stream.match(/[a-zA-Z_!]+\!\(/)) return 'function'
|
|
|
|
|
|
if (stream.match(/[a-zA-Z_!]+\(/)) return 'function';
|
|
|
|
// Field access
|
|
if (stream.match(/\.[a-zA-Z_]\w*/)) return 'propertyName'
|
|
|
|
// Operators
|
|
if (stream.match(/[=><!~?&%|+\-*\/\^\.,\:;()[\]{}]+/)) return 'operator'
|
|
|
|
|
|
// // Identifiers and function names
|
|
// if (stream.match(/[a-zA-Z_][\w]*/)) {
|
|
// const word = stream.current();
|
|
// if (vrlFunctions.includes(word)) return 'function';
|
|
// return 'variableName';
|
|
// }
|
|
|
|
if (stream.match(/\s+/)) return null; // whitespace
|
|
|
|
|
|
// Advance stream
|
|
stream.next()
|
|
return null
|
|
},
|
|
|
|
languageData: {
|
|
commentTokens: { line: '#' },
|
|
closeBrackets: { brackets: ['(', '[', '{', '"', "'", 'r"', 's"', 't"', 'r\'', 's\'', 't\''] },
|
|
indentOnInput: /^\s*[})\]]$/
|
|
}
|
|
})
|
|
|
|
// VRL theme colors (matching the provided image)
|
|
export const vrlHighlightStyle = HighlightStyle.define([
|
|
{ tag: t.comment, color: '#4CAF50', class: 'cm-vrl-comment' }, // green
|
|
{ tag: t.keyword, color: '#569cd6', class: 'cm-vrl-keyword' }, // purple
|
|
{ tag: t.number, color: '#b5cea8', class: 'cm-vrl-number' }, // blue
|
|
{ tag: t.bool, color: '#0000ff', class: 'cm-vrl-bool' }, // blue
|
|
{ tag: t.null, color: '#b5cea8', class: 'cm-vrl-null' }, // blue
|
|
{ tag: t.string, color: '#a31515', class: 'cm-vrl-string' }, // red
|
|
{ tag: t.regexp, color: '#ce9178', class: 'cm-vrl-regexp' }, // red (for VRL regex strings)
|
|
{ tag: t.variableName, color: '#d4d4d4', class: 'cm-vrl-variableName' }, // black
|
|
{ tag: t.definition(t.variableName), color: '#569cd6', class: 'cm-vrl-definition' }, // black
|
|
{ tag: t.propertyName, color: '#d4d4d4', class: 'cm-vrl-propertyName' }, // black
|
|
{ tag: t.operator, color: '#d4d4d4', class: 'cm-vrl-operator' }, // black
|
|
{ tag: t.punctuation, color: '#d4d4d4', class: 'cm-vrl-punctuation' }, // black
|
|
{ tag: t.function(t.propertyName), color: '#569cd6'}, // blue
|
|
{ tag: t.function(t.variableName), color: '#569cd6'}, // blue
|
|
],
|
|
{
|
|
themeType: "light"
|
|
})
|
|
|
|
// VRL theme colors (matching the provided image)
|
|
export const vrlHighDarkStyle = HighlightStyle.define([
|
|
{ tag: t.comment, color: '#608b4e', class: 'cm-vrl-comment' }, // green
|
|
{ tag: t.keyword, color: '#569cd6', class: 'cm-vrl-keyword' }, // purple
|
|
{ tag: t.number, color: '#b5cea8', class: 'cm-vrl-number' }, // blue
|
|
{ tag: t.bool, color: '#b5cea8', class: 'cm-vrl-bool' }, // blue
|
|
{ tag: t.null, color: '#b5cea8', class: 'cm-vrl-null' }, // blue
|
|
{ tag: t.string, color: '#ce9178', class: 'cm-vrl-string' }, // red
|
|
{ tag: t.regexp, color: '#ce9178', class: 'cm-vrl-regexp' }, // red (for VRL regex strings)
|
|
{ tag: t.variableName, color: '#d4d4d4', class: 'cm-vrl-variableName' }, // black
|
|
{ tag: t.definition(t.variableName), color: '#569cd6', class: 'cm-vrl-definition' }, // black
|
|
{ tag: t.propertyName, color: '#d4d4d4', class: 'cm-vrl-propertyName' }, // black
|
|
{ tag: t.operator, color: '#d4d4d4', class: 'cm-vrl-operator' }, // black
|
|
{ tag: t.punctuation, color: '#d4d4d4', class: 'cm-vrl-punctuation' }, // black
|
|
{ tag: t.function(t.propertyName), color: '#569cd6', class: 'cm-vrl-function' }, // blue
|
|
{ tag: t.function(t.variableName), color: '#569cd6', class: 'cm-vrl-function' }, // blue
|
|
],
|
|
{
|
|
themeType: "dark",
|
|
})
|
|
|
|
// Language support for VRL
|
|
export function vrl() {
|
|
return new LanguageSupport(vrlLanguage, [
|
|
syntaxHighlighting(vrlHighlightStyle),
|
|
syntaxHighlighting(vrlHighDarkStyle),
|
|
])
|
|
}
|