Files
js-sha1/tests/esm-test.mjs
T
Yi-Cyuan ChenandClaude Opus 5.5 3e1a92f2a4 ### Added
- ESM builds and package `exports`.

### Fixed
- Incorrect hash for strings with unpaired UTF-16 surrogates; they are now encoded as U+FFFD, the same as `TextEncoder`.
- Detect browsers with a `process` polyfill (e.g. BrowserFS) and Electron renderers as non-Node.js environments.

### Changed
- Replace Travis CI with GitHub Actions.
- Update dev dependencies and fix security issues.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 13:58:54 +08:00

26 lines
886 B
JavaScript

import { createRequire } from 'module';
import expect from 'expect.js';
import * as esm from '../build/sha1.mjs';
import * as esmMin from '../build/sha1.min.mjs';
import * as esmNode from '../build/sha1.node.mjs';
import * as pkg from 'js-sha1';
const require = createRequire(import.meta.url);
globalThis.expect = expect;
[['build/sha1.mjs', esm], ['build/sha1.min.mjs', esmMin], ['build/sha1.node.mjs', esmNode], ['js-sha1', pkg]].forEach(([name, mod]) => {
describe('ESM ' + name, () => {
it('should export the named member matching the default export', () => {
expect(mod.sha1).to.be(mod.default);
expect(mod.default.hmac).to.be.a('function');
});
});
globalThis.sha1 = mod.default;
delete require.cache[require.resolve('./test.js')];
delete require.cache[require.resolve('./hmac-test.js')];
require('./test.js');
require('./hmac-test.js');
});