migrate-imports.test.js 864 B

12345678910111213141516171819202122232425
  1. const path = require('path');
  2. const { promises: fs, constants: { F_OK } } = require('fs');
  3. const { expect } = require('chai');
  4. const { pathUpdates, updateImportPaths } = require('../scripts/migrate-imports.js');
  5. describe('migrate-imports.js', function () {
  6. it('every new path exists', async function () {
  7. for (const p of Object.values(pathUpdates)) {
  8. await fs.access(path.join('contracts', p), F_OK);
  9. }
  10. });
  11. it('replaces import paths in a file', async function () {
  12. const source = `
  13. import '@openzeppelin/contracts/math/Math.sol';
  14. import '@openzeppelin/contracts-upgradeable/math/MathUpgradeable.sol';
  15. `;
  16. const expected = `
  17. import '@openzeppelin/contracts/utils/math/Math.sol';
  18. import '@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol';
  19. `;
  20. expect(updateImportPaths(source)).to.equal(expected);
  21. });
  22. });