Skip to content

Latest commit

 

History

History
325 lines (251 loc) · 7 KB

File metadata and controls

325 lines (251 loc) · 7 KB

explicit-async

Converts all page object implicit async actions(old testing style) to the explicit async actions(ember@3 testing style).

Usage

npx ember-page-object-codemod explicit-async ./tests/**/*-test.js ./tests/pages

# or

yarn global add ember-page-object-codemod
ember-page-object-codemod explicit-async ./tests/**/*-test.js ./tests/pages

Input / Output


arrow-test

Input (arrow-test.input.js):

import page from '/pages/page';

test('test', (assert) => {
    page.visit({ id });
});

Output (arrow-test.output.js):

import page from '/pages/page';

test('test', async assert => {
    await page.visit({ id });
});

class

Input (class.input.js):

export default {
    member() {
        p.aCall();
        p.a.aCall();
    },

    thisMember() {
        this.aCall();
        this.a.aCall();
    },

    inCallExpression() {
        eq(A.as());
    }
}
  

Output (class.output.js):

export default {
    async member() {
        await p.aCall();
        await p.a.aCall();
    },

    async thisMember() {
        await this.aCall();
        await this.a.aCall();
    },

    inCallExpression() {
        eq(A.as());
    }
}
  

collections

Input (collections.input.js):

import { aPage } from 'my-app/tests/pages';

const [ first ] = aPage.items;
const second = aPage.objectAt(1);
const third = aPage.items[2];

test('collection works', function(assert) {
  aPage.more[0].click();
  first.click();
  second.click();
  third.more[0].click();
})

Output (collections.output.js):

import { aPage } from 'my-app/tests/pages';

const [ first ] = aPage.items;
const second = aPage.objectAt(1);
const third = aPage.items[2];

test('collection works', async function(assert) {
  await aPage.more[0].click();
  await first.click();
  await second.click();
  await third.more[0].click();
})

definition

Input (definition.input.js):

export default {
    scope: '.selector',

    act() {
        this.click();
    },

    subComponent: {
        scope: '.sub-selector',

        act(value) {
            this.focus();
            this.fillIn(value);
        }
    }
};

Output (definition.output.js):

export default {
    scope: '.selector',

    async act() {
        await this.click();
    },

    subComponent: {
        scope: '.sub-selector',

        async act(value) {
            await this.focus();
            await this.fillIn(value);
        }
    }
};

destruction

Input (destruction.input.js):

import aPage from 'my-app/tests/pages';

test('destruction works', function(assert) {
  const { aComponent } = aPage;

  aComponent.click();
})

Output (destruction.output.js):

import aPage from 'my-app/tests/pages';

test('destruction works', async function(assert) {
  const { aComponent } = aPage;

  await aComponent.click();
})

known-sync-methods

Input (known-sync-methods.input.js):

import aPage from 'my-app/tests/pages';

test('should not be affected', async function(assert) {
  aPage.render();
  aPage.setContext();
  aPage.removeContext();
  aPage.useNativeEvents();
  aPage.objectAt();
  aPage.toArray();
  aPage.map();
  aPage.mapBy();
  aPage.forEach();
  aPage.filter();
})

Output (known-sync-methods.output.js):

import aPage from 'my-app/tests/pages';

test('should not be affected', async function(assert) {
  aPage.render();
  aPage.setContext();
  aPage.removeContext();
  aPage.useNativeEvents();
  aPage.objectAt();
  aPage.toArray();
  aPage.map();
  aPage.mapBy();
  aPage.forEach();
  aPage.filter();
})

nesting

Input (nesting.input.js):

import A from 'somewhere';
import complexPage from '../pages';

let items = A(['a', 'b']);

test('complex collection with a nested scope', function(assert) {
    const aCollection = complexPage.items.objectAt(0).subitems.objectAt(0).subbitems.objectAt(0);

    items.forEach(function(i) {
        aCollection.click(i);
    });
});

Output (nesting.output.js):

import A from 'somewhere';
import complexPage from '../pages';

let items = A(['a', 'b']);

test('complex collection with a nested scope', function(assert) {
    const aCollection = complexPage.items.objectAt(0).subitems.objectAt(0).subbitems.objectAt(0);

    items.forEach(async function(i) {
        await aCollection.click(i);
    });
});

test

Input (test.input.js):

import page from '/pages/page';

test('test', function(assert) {
    page.visit({ id });

    assert.ok(page.contains('some text'));
});

Output (test.output.js):

import page from '/pages/page';

test('test', async function(assert) {
    await page.visit({ id });

    assert.ok(page.contains('some text'));
});

with-chaining

Input (with-chaining.input.js):

export default {
    scope: '.selector',

    act() {
        this.focus().blur();
    }
}

Output (with-chaining.output.js):

export default {
    scope: '.selector',

    async act() {
        await this.focus().blur();
    }
}