|
| 1 | +// inspired by https://github.com/ember-codemods/ember-module-migrator/blob/master/test/engines/classic-test.js |
| 2 | + |
| 3 | +var path = require("path"); |
| 4 | +var assert = require("power-assert"); |
| 5 | +var assertDiff = require('assert-diff'); |
| 6 | +var fixturify = require("fixturify"); |
| 7 | +var fse = require("fs-extra"); |
| 8 | +var Migrator = require('../lib/migrator'); |
| 9 | + |
| 10 | +assertDiff.options.strict = true; |
| 11 | + |
| 12 | +describe("Migrator", function() { |
| 13 | + var tmpPath = "tmp/process-files"; |
| 14 | + var fixturesPath = path.resolve(__dirname, "fixtures"); |
| 15 | + |
| 16 | + beforeEach(function() { |
| 17 | + fse.mkdirsSync(tmpPath); |
| 18 | + }); |
| 19 | + |
| 20 | + afterEach(function() { |
| 21 | + fse.removeSync(tmpPath); |
| 22 | + }); |
| 23 | + |
| 24 | + var entries = fse.readdirSync(fixturesPath); |
| 25 | + |
| 26 | + entries.forEach(async function(entry) { |
| 27 | + it(`should migrate ${entry} fixture properly`, async function() { |
| 28 | + var fixturePath = path.join(fixturesPath, entry); |
| 29 | + var input = require(fixturePath + "/input"); |
| 30 | + var expected = require(fixturePath + "/output"); |
| 31 | + var migratorConfig = {}; |
| 32 | + try { |
| 33 | + migratorConfig = require(fixturePath + "/config"); |
| 34 | + } catch (e) { |
| 35 | + // fixture uses default config... |
| 36 | + } |
| 37 | + |
| 38 | + fixturify.writeSync(tmpPath, input); |
| 39 | + |
| 40 | + var migratorOptions = Object.assign( |
| 41 | + { projectRoot: tmpPath }, |
| 42 | + migratorConfig |
| 43 | + ); |
| 44 | + |
| 45 | + var migrator = new Migrator(migratorOptions); |
| 46 | + await migrator.execute(); |
| 47 | + |
| 48 | + var actual = fixturify.readSync(tmpPath); |
| 49 | + assertDiff.deepEqual(actual, expected, "the codemod should work as expected"); |
| 50 | + |
| 51 | + await migrator.execute(); |
| 52 | + assertDiff.deepEqual(actual, expected, "the codemod should be idempotent"); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
0 commit comments