mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
chore(telemetry): Migrate tests to node:test
(#9886)
* Migrate Telemetry tests to node:test * Remove fallback to chai * Remove chai and mocha dependencies * Fix trailing comma * Fix pnpm-lock.yaml desync * Add back old tests with progression * Remove mocha tests again * Remove trailing comma
This commit is contained in:
parent
2ac371404d
commit
c1a3e80dfe
3 changed files with 32 additions and 32 deletions
|
@ -23,11 +23,9 @@
|
|||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
||||
"test": "mocha --exit --timeout 20000 test/"
|
||||
"test": "astro-scripts test \"test/**/*.test.js\""
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"files": ["dist"],
|
||||
"dependencies": {
|
||||
"ci-info": "^4.0.0",
|
||||
"debug": "^4.3.4",
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
import { GlobalConfig } from '../dist/config.js';
|
||||
|
||||
describe('GlobalConfig', () => {
|
||||
it('initializes when expected arguments are given', () => {
|
||||
const config = new GlobalConfig({ name: 'TEST_NAME' });
|
||||
expect(config).to.be.instanceOf(GlobalConfig);
|
||||
assert(config instanceof GlobalConfig);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it, before, after } from 'node:test';
|
||||
import { AstroTelemetry } from '../dist/index.js';
|
||||
|
||||
function setup() {
|
||||
|
@ -29,55 +30,55 @@ describe('AstroTelemetry', () => {
|
|||
});
|
||||
it('initializes when expected arguments are given', () => {
|
||||
const { telemetry } = setup();
|
||||
expect(telemetry).to.be.instanceOf(AstroTelemetry);
|
||||
assert(telemetry instanceof AstroTelemetry);
|
||||
});
|
||||
it('does not record event if disabled', async () => {
|
||||
const { telemetry, config, logs } = setup();
|
||||
telemetry.setEnabled(false);
|
||||
const [key] = Array.from(config.keys());
|
||||
expect(key).not.to.be.undefined;
|
||||
expect(config.get(key)).to.be.false;
|
||||
expect(telemetry.enabled).to.be.false;
|
||||
expect(telemetry.isDisabled).to.be.true;
|
||||
assert.notEqual(key, undefined);
|
||||
assert.equal(config.get(key), false);
|
||||
assert.equal(telemetry.enabled, false);
|
||||
assert.equal(telemetry.isDisabled, true);
|
||||
const result = await telemetry.record(['TEST']);
|
||||
expect(result).to.be.undefined;
|
||||
assert.equal(result, undefined);
|
||||
const [log] = logs;
|
||||
expect(log).not.to.be.undefined;
|
||||
expect(logs.join('')).to.match(/disabled/);
|
||||
assert.notEqual(log, undefined);
|
||||
assert.match(logs.join(''), /disabled/);
|
||||
});
|
||||
it('records event if enabled', async () => {
|
||||
const { telemetry, config, logs } = setup();
|
||||
telemetry.setEnabled(true);
|
||||
const [key] = Array.from(config.keys());
|
||||
expect(key).not.to.be.undefined;
|
||||
expect(config.get(key)).to.be.true;
|
||||
expect(telemetry.enabled).to.be.true;
|
||||
expect(telemetry.isDisabled).to.be.false;
|
||||
assert.notEqual(key, undefined);
|
||||
assert.equal(config.get(key), true);
|
||||
assert.equal(telemetry.enabled, true);
|
||||
assert.equal(telemetry.isDisabled, false);
|
||||
await telemetry.record(['TEST']);
|
||||
expect(logs.length).to.equal(2);
|
||||
assert.equal(logs.length, 2);
|
||||
});
|
||||
it('respects disable from notify', async () => {
|
||||
const { telemetry, config, logs } = setup();
|
||||
await telemetry.notify(() => false);
|
||||
const [key] = Array.from(config.keys());
|
||||
expect(key).not.to.be.undefined;
|
||||
expect(config.get(key)).to.be.false;
|
||||
expect(telemetry.enabled).to.be.false;
|
||||
expect(telemetry.isDisabled).to.be.true;
|
||||
assert.notEqual(key, undefined);
|
||||
assert.equal(config.get(key), false);
|
||||
assert.equal(telemetry.enabled, false);
|
||||
assert.equal(telemetry.isDisabled, true);
|
||||
const [log] = logs;
|
||||
expect(log).not.to.be.undefined;
|
||||
expect(logs.join('')).to.match(/disabled/);
|
||||
assert.notEqual(log, undefined);
|
||||
assert.match(logs.join(''), /disabled/);
|
||||
});
|
||||
it('respects enable from notify', async () => {
|
||||
const { telemetry, config, logs } = setup();
|
||||
await telemetry.notify(() => true);
|
||||
const [key] = Array.from(config.keys());
|
||||
expect(key).not.to.be.undefined;
|
||||
expect(config.get(key)).to.be.true;
|
||||
expect(telemetry.enabled).to.be.true;
|
||||
expect(telemetry.isDisabled).to.be.false;
|
||||
assert.notEqual(key, undefined);
|
||||
assert.equal(config.get(key), true);
|
||||
assert.equal(telemetry.enabled, true);
|
||||
assert.equal(telemetry.isDisabled, false);
|
||||
const [log] = logs;
|
||||
expect(log).not.to.be.undefined;
|
||||
expect(logs.join('')).to.match(/enabled/);
|
||||
assert.notEqual(log, undefined);
|
||||
assert.match(logs.join(''), /enabled/);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue