Skip to content

Commit

Permalink
refactor(test/prefer-native): use co instead of async fn
Browse files Browse the repository at this point in the history
  • Loading branch information
buschtoens committed Nov 15, 2018
1 parent 9e25f5f commit 2a32243
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
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);
})
}))
}
});
});

0 comments on commit 2a32243

Please sign in to comment.