Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(test/prefer-native): use co instead of async fn & run in CI #162

Merged
merged 2 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ install:

script:
- yarn lint:js
- yarn test:node
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"broccoli-asset-rev": "^2.4.5",
"broccoli-test-helper": "^1.2.0",
"chai": "^4.1.2",
"co": "^4.6.0",
"ember-cli": "~3.0.2",
"ember-cli-dependency-checker": "^3.0.0",
"ember-cli-eslint": "^4.2.1",
Expand Down
25 changes: 13 additions & 12 deletions test/prefer-native-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const helpers = require('broccoli-test-helper');
const vm = require('vm');
const fs = require('fs');
const RSVP = require('rsvp');
const co = require('co');

const testCode = `
define('fetch-test', ['fetch'], function(_fetch) {
Expand All @@ -29,21 +30,21 @@ require('fetch-test');
output = helpers.createBuilder(subject);
});

afterEach(async function() {
await output.dispose();
});
afterEach(co.wrap(function* () {
yield output.dispose();
}));

it('preferNative is built into vendor file', async function() {
await output.build();
it('preferNative is built into vendor file', co.wrap(function*() {
yield output.build();
let files = output.read();
expect(files).to.have.all.keys('ember-fetch.js');
expect(files['ember-fetch.js']).to.include(`var preferNative = ${preferNative}`);
});
}));

it(`${
preferNative ? 'Prefers' : "Doesn't prefer"
} native fetch as specified`, async function() {
await output.build();
} native fetch as specified`, co.wrap(function*() {
yield output.build();
let emberFetchCode = output.read()['ember-fetch.js'];
const amdLoaderCode = fs.readFileSync(require.resolve('loader.js'));
const sandbox = {
Expand All @@ -59,11 +60,11 @@ require('fetch-test');
const code = amdLoaderCode + emberFetchCode + testCode;
vm.runInContext(code, sandbox);
expect(sandbox.__result).to.equal(preferNative);
});
}));

if (preferNative === true) {
it('Has fetch poly fill even if fetch is not there', async function() {
await output.build();
it('Has fetch poly fill even if fetch is not there', co.wrap(function*() {
yield output.build();
let emberFetchCode = output.read()['ember-fetch.js'];
const amdLoaderCode = fs.readFileSync(require.resolve('loader.js'));
const sandbox = {
Expand All @@ -87,7 +88,7 @@ require('fetch-test');
const code = amdLoaderCode + emberFetchCode + testCodeForNonFetch;
vm.runInContext(code, sandbox);
expect(sandbox.window.__result).to.equal(true);
})
}))
}
});
});