|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import babelParser from 'recast/parsers/babel.js'; |
| 3 | +import { parse, print } from 'recast'; |
| 4 | +import transformTestHelper from './test-helper.js'; |
| 5 | + |
| 6 | +async function parseAndApply(input) { |
| 7 | + let ast = await parse(input, { parser: babelParser }); |
| 8 | + ast = await transformTestHelper(ast); |
| 9 | + return print(ast).code; |
| 10 | +} |
| 11 | + |
| 12 | +describe('test-helper() function', () => { |
| 13 | + it('transforms a default test-helper', async () => { |
| 14 | + expect( |
| 15 | + await parseAndApply(` |
| 16 | + import Application from 'my-empty-classic-app/app'; |
| 17 | + import config from 'my-empty-classic-app/config/environment'; |
| 18 | + import * as QUnit from 'qunit'; |
| 19 | + import { setApplication } from '@ember/test-helpers'; |
| 20 | + import { setup } from 'qunit-dom'; |
| 21 | + import { loadTests } from 'ember-qunit/test-loader'; |
| 22 | + import { start, setupEmberOnerrorValidation } from 'ember-qunit'; |
| 23 | + |
| 24 | + setApplication(Application.create(config.APP)); |
| 25 | + |
| 26 | + setup(QUnit.assert); |
| 27 | + setupEmberOnerrorValidation(); |
| 28 | + loadTests(); |
| 29 | + start(); |
| 30 | + `), |
| 31 | + ).toMatchInlineSnapshot(` |
| 32 | + " |
| 33 | + import Application from 'my-empty-classic-app/app'; |
| 34 | + import config from 'my-empty-classic-app/config/environment'; |
| 35 | + import * as QUnit from 'qunit'; |
| 36 | + import { setApplication } from '@ember/test-helpers'; |
| 37 | + import { setup } from 'qunit-dom'; |
| 38 | + import { start as qunitStart, setupEmberOnerrorValidation } from 'ember-qunit'; |
| 39 | +
|
| 40 | + export function start() { |
| 41 | + setApplication(Application.create(config.APP)); |
| 42 | +
|
| 43 | + setup(QUnit.assert); |
| 44 | + setupEmberOnerrorValidation(); |
| 45 | + qunitStart(); |
| 46 | + } |
| 47 | + " |
| 48 | + `); |
| 49 | + }); |
| 50 | +}); |
0 commit comments