|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +define(['chai'], function (chai) { |
| 4 | + const { expect } = chai; |
| 5 | + const fs = require('fs'); |
| 6 | + const path = require('path'); |
| 7 | + const repoRoot = path.resolve(__dirname, '..', '..'); |
| 8 | + |
| 9 | + describe('legacy v1 import-path shims', function () { |
| 10 | + function loadShim(relPath) { |
| 11 | + const abs = path.join(repoRoot, relPath); |
| 12 | + delete require.cache[abs]; |
| 13 | + require(abs); |
| 14 | + } |
| 15 | + |
| 16 | + it("'ably/promises' shim throws naming the v1 entry point and migration guide", function () { |
| 17 | + expect(() => loadShim('promises.js')) |
| 18 | + .to.throw(Error) |
| 19 | + .with.property('message') |
| 20 | + .that.matches(/'ably\/promises' was the v1 entry point/) |
| 21 | + .and.matches(/migration-guides\/v2\/lib\.md/); |
| 22 | + }); |
| 23 | + |
| 24 | + it("'ably/callbacks' shim throws naming the v1 callback API and migration guide", function () { |
| 25 | + expect(() => loadShim('callbacks.js')) |
| 26 | + .to.throw(Error) |
| 27 | + .with.property('message') |
| 28 | + .that.matches(/'ably\/callbacks' was the v1 callback API entry point/) |
| 29 | + .and.matches(/migration-guides\/v2\/lib\.md/); |
| 30 | + }); |
| 31 | + |
| 32 | + it('package.json exports map wires the legacy subpaths to the shim files and their types', function () { |
| 33 | + const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8')); |
| 34 | + |
| 35 | + expect(pkg.exports['./promises'], "exports['./promises']").to.deep.equal({ |
| 36 | + types: './promises.d.ts', |
| 37 | + default: './promises.js', |
| 38 | + }); |
| 39 | + expect(pkg.exports['./callbacks'], "exports['./callbacks']").to.deep.equal({ |
| 40 | + types: './callbacks.d.ts', |
| 41 | + default: './callbacks.js', |
| 42 | + }); |
| 43 | + |
| 44 | + for (const file of ['promises.js', 'promises.d.ts', 'callbacks.js', 'callbacks.d.ts']) { |
| 45 | + expect(fs.existsSync(path.join(repoRoot, file)), file).to.equal(true); |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + it("'files' array ships the legacy shim files in the published package", function () { |
| 50 | + const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8')); |
| 51 | + for (const file of ['promises.js', 'promises.d.ts', 'callbacks.js', 'callbacks.d.ts']) { |
| 52 | + expect(pkg.files, `files[] should include ${file}`).to.include(file); |
| 53 | + } |
| 54 | + }); |
| 55 | + }); |
| 56 | +}); |
0 commit comments