Skip to content

Commit

Permalink
@0.14.2 - update devdeps, copyright
Browse files Browse the repository at this point in the history
  • Loading branch information
localnerve committed Jan 7, 2024
1 parent 1a7f1bc commit 27c6802
Show file tree
Hide file tree
Showing 7 changed files with 1,114 additions and 1,341 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
@@ -1,4 +1,4 @@
Copyright (c) 2016 - 2023 Alex Grant, LocalNerve LLC
Copyright (c) 2016 - 2024 Alex Grant, LocalNerve LLC
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2,375 changes: 1,073 additions & 1,302 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "element-size-reporter",
"version": "0.14.1",
"version": "0.14.2",
"description": "Reports width, height, and top for selected DOM elements",
"main": "dist/index.js",
"exports": {
Expand Down Expand Up @@ -44,18 +44,17 @@
"test"
],
"devDependencies": {
"@babel/cli": "^7.23.0",
"@babel/core": "^7.23.2",
"@babel/eslint-parser": "7.22.15",
"@babel/preset-env": "^7.23.2",
"@babel/preset-react": "^7.22.15",
"@babel/register": "^7.22.15",
"c8": "^8.0.1",
"chai": "^4.3.10",
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.7",
"@babel/eslint-parser": "7.23.3",
"@babel/preset-env": "^7.23.7",
"@babel/preset-react": "^7.23.3",
"@babel/register": "^7.23.7",
"c8": "^9.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.51.0",
"eslint": "^8.56.0",
"eslint-plugin-react": "^7.33.2",
"jsdom": "^22.1.0",
"jsdom": "^23.1.0",
"lodash": "^4.17.21",
"mocha": "^10.2.0",
"precommit-hook": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.js
@@ -1,5 +1,5 @@
/***
* Copyright (c) 2016 - 2023 Alex Grant (@localnerve), LocalNerve LLC
* Copyright (c) 2016 - 2024 Alex Grant (@localnerve), LocalNerve LLC
* Copyrights licensed under the BSD License.
* See the accompanying LICENSE file for terms.
*
Expand Down
2 changes: 1 addition & 1 deletion src/tests/fixtures/Simple.jsx
@@ -1,5 +1,5 @@
/***
* Copyright (c) 2016 - 2023 Alex Grant (@localnerve), LocalNerve LLC
* Copyright (c) 2016 - 2024 Alex Grant (@localnerve), LocalNerve LLC
* Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
*
* React usage example and test fixture.
Expand Down
51 changes: 27 additions & 24 deletions src/tests/unit/index.js
@@ -1,10 +1,10 @@
/***
* Copyright (c) 2016 - 2023 Alex Grant (@localnerve), LocalNerve LLC
* Copyright (c) 2016 - 2024 Alex Grant (@localnerve), LocalNerve LLC
* Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
*/
/* eslint-env browser */
/* global before, beforeEach, after, afterEach, describe, it */
import { expect } from 'chai';
import * as assert from 'node:assert';
import React from 'react';
import ReactDOM from 'react-dom/client';
import { act } from 'react-dom/test-utils';
Expand All @@ -26,10 +26,10 @@ describe('sizeReporter', () => {
it('should report and have expected report items with correct types',
(done) => {
const reporter = createSizeReporter('.nothing', (data) => {
expect(typeof data.width).to.equal('number');
expect(typeof data.height).to.equal('number');
expect(typeof data.top).to.equal('number');
expect(typeof data.accumulate).to.equal('boolean');
assert.equal(typeof data.width, 'number');
assert.equal(typeof data.height, 'number');
assert.equal(typeof data.top, 'number');
assert.equal(typeof data.accumulate, 'boolean');
done();
}, {
reportWidth: true,
Expand All @@ -43,15 +43,15 @@ describe('sizeReporter', () => {

describe('bad args', () => {
it('should throw if no selector supplied', () => {
expect(function () {
assert.throws(function () {
createSizeReporter('', () => {});
}).to.throw(Error);
});
});

it('should throw if no reporter function supplied', () => {
expect(function () {
assert.throws(function () {
createSizeReporter('.nothing', 'bad');
}).to.throw(Error);
});
});
});

Expand All @@ -78,18 +78,21 @@ describe('sizeReporter', () => {
});

it('should render and execute action', async () => {
let result;
await act(() => {
const element = React.createElement(Simple);
ReactDOM.createRoot(container).render(element);
});

const result = document.querySelector('.contained');
expect(result.textContent).to.match(/Simple Test/);
await act(() => {
result = document.querySelector('.contained');
assert.match(result.textContent, /Simple Test/);
});

return new Promise(res => {
setTimeout(() => {
// Action test. Executes on componentDidMount so action should've run.
expect(result.textContent).to.match(/Action/);
assert.match(result.textContent, /Action/);
res();
}, 250);
});
Expand All @@ -106,10 +109,10 @@ describe('sizeReporter', () => {
function handleReport (data) {
if (reportCall === 0) {
// First time, you want to overwrite the data.
expect(data.accumulate).to.be.false;
assert.equal(data.accumulate, false);
} else {
// After that, you're accumulating.
expect(data.accumulate).to.be.true;
assert.equal(data.accumulate, true);
}

reportCall++;
Expand Down Expand Up @@ -171,12 +174,12 @@ describe('sizeReporter', () => {

it('should compute values as expected', (done) => {
const reporter = createSizeReporter('.mock', (data) => {
expect(data.width).to.equal(Math.round(right - left));
expect(data.height).to.equal(Math.round(bottom - top));
expect(data.top).to.equal(Math.round(
assert.equal(data.width, Math.round(right - left));
assert.equal(data.height, Math.round(bottom - top));
assert.equal(data.top, Math.round(
top + (pageYOffset - domProps.clientTop)
));
expect(data.accumulate).to.equal(false);
assert.equal(data.accumulate, false);
done();
}, {
reportWidth: true,
Expand All @@ -191,7 +194,7 @@ describe('sizeReporter', () => {
const multiple = 10;

const reporter = createSizeReporter('.mock', (data) => {
expect(data.width).to.equal(
assert.equal(data.width,
Math.ceil((right - left)/multiple) * multiple
);
done();
Expand All @@ -209,10 +212,10 @@ describe('sizeReporter', () => {
const multiple = 10;

const reporter = createSizeReporter('.mock', (data) => {
expect(data.top).to.equal(
assert.equal(data.top,
Math.floor((top + (pageYOffset - domProps.clientTop))/multiple) * multiple
);
expect(data.top - (pageYOffset - domProps.clientTop)).to.be.below(top);
assert.equal((data.top - (pageYOffset - domProps.clientTop)) < top, true);
done();
}, {
reportTop: true,
Expand All @@ -226,7 +229,7 @@ describe('sizeReporter', () => {

it('should handle missing grow option with round', (done) => {
const reporter = createSizeReporter('.mock', (data) => {
expect(data.width).to.equal(
assert.equal(data.width,
Math.round(right - left)
);
done();
Expand All @@ -239,7 +242,7 @@ describe('sizeReporter', () => {

it('should handle missing grow option prop without round', (done) => {
const reporter = createSizeReporter('.mock', (data) => {
expect(data.width).to.equal(
assert.equal(data.width,
Math.ceil(right - left)
);
done();
Expand Down
2 changes: 1 addition & 1 deletion src/tests/utils/testdom.js
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2016 - 2023 Alex Grant (@localnerve), LocalNerve LLC
* Copyright (c) 2016 - 2024 Alex Grant (@localnerve), LocalNerve LLC
* Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
*
* Start/stop jsdom environment
Expand Down

0 comments on commit 27c6802

Please sign in to comment.