Skip to content

Commit

Permalink
Support Node 18
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinwcyu committed Sep 14, 2023
1 parent a56fdf2 commit f2e2fac
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 188 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
18
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@grafana/data": "9.2.5",
"@grafana/e2e": "9.2.5",
"@grafana/e2e-selectors": "9.2.5",
"@grafana/eslint-config": "^5.1.0",
"@grafana/eslint-config": "^6.0.1",
"@grafana/runtime": "9.2.5",
"@grafana/tsconfig": "^1.2.0-rc1",
"@grafana/ui": "9.2.5",
Expand All @@ -50,7 +50,7 @@
"css-loader": "^6.7.1",
"eslint": "8.26.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-jsdoc": "^46.7.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.26.1",
"eslint-plugin-react-hooks": "^4.2.0",
Expand Down
43 changes: 25 additions & 18 deletions src/DataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DataSource } from './DataSource';
import { DataSourceInstanceSettings, PluginMeta, ScopedVar, ScopedVars } from '@grafana/data';
import { QueryType, SitewiseOptions, SitewiseQuery } from './types';


const testInstanceSettings = (
overrides?: Partial<DataSourceInstanceSettings<SitewiseOptions>>
): DataSourceInstanceSettings<SitewiseOptions> => ({
Expand All @@ -21,26 +20,26 @@ jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
getTemplateSrv: () => {
// ref: https://github.com/grafana/grafana/blob/main/public/app/features/variables/utils.ts#L17
const variableRegex = /\$(\w+)|\[\[(\w+?)(?::(\w+))?\]\]|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/g;
const variableRegex = /\$(\w+)|\[\[(\w+?)(?::(\w+))?\]\]|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/g;
const globalVars: ScopedVars = {
assetIdConstant: {text: 'valueConstant', value: 'valueConstant'},
assetIdArray: {text: ['array1', 'array2', 'array3'], value: ['array1', 'array2', 'array3']}
assetIdConstant: { text: 'valueConstant', value: 'valueConstant' },
assetIdArray: { text: ['array1', 'array2', 'array3'], value: ['array1', 'array2', 'array3'] },
};
return {
// Approximate mock of replace function, with 'csv' format
// ref: https://github.com/grafana/grafana/blob/main/public/app/features/templating/template_srv.mock.ts#L30
// ref: https://github.com/grafana/grafana/blob/main/public/app/features/templating/template_srv.mock.ts#L30
replace(str: string, scopedVars?: ScopedVars, format?: string | Function) {
return str.replace(variableRegex, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
const variableName = var1 || var2 || var3;
let varMatch: ScopedVar | undefined;
if (!!scopedVars) {
varMatch = scopedVars[variableName];
}
varMatch = varMatch ?? globalVars[variableName];
if (Array.isArray(varMatch.value)) {
return varMatch.value.join(',');
}
return varMatch.value;
const variableName = var1 || var2 || var3;
let varMatch: ScopedVar | undefined;
if (!!scopedVars) {
varMatch = scopedVars[variableName];
}
varMatch = varMatch ?? globalVars[variableName];
if (Array.isArray(varMatch.value)) {
return varMatch.value.join(',');
}
return varMatch.value;
});
},
};
Expand Down Expand Up @@ -104,7 +103,11 @@ describe('Sitewise Datasource', () => {
region: 'default',
propertyId: '',
};
expect(datasource.applyTemplateVariables(query, { assetIdConstant: { text: 'scopedValueConstant', value: 'scopedValueConstant' } })).toEqual({
expect(
datasource.applyTemplateVariables(query, {
assetIdConstant: { text: 'scopedValueConstant', value: 'scopedValueConstant' },
})
).toEqual({
...query,
assetIds: ['scopedValueConstant'],
});
Expand All @@ -119,10 +122,14 @@ describe('Sitewise Datasource', () => {
region: 'default',
propertyId: '',
};
expect(datasource.applyTemplateVariables(query, { assetIdConstant: { text: 'scopedValueConstant', value: 'scopedValueConstant' } })).toEqual({
expect(
datasource.applyTemplateVariables(query, {
assetIdConstant: { text: 'scopedValueConstant', value: 'scopedValueConstant' },
})
).toEqual({
...query,
assetIds: ['scopedValueConstant', 'noVar', 'array1', 'array2', 'array3'],
});
});
});
});
});
Loading

0 comments on commit f2e2fac

Please sign in to comment.