Skip to content

Commit

Permalink
Merge pull request #162 from buschtoens/async-to-co
Browse files Browse the repository at this point in the history
refactor(test/prefer-native): use co instead of async fn & run in CI
  • Loading branch information
Turbo87 authored Nov 15, 2018
2 parents 6ef6cd9 + ed427a8 commit f4042ea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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);
})
}))
}
});
});

0 comments on commit f4042ea

Please sign in to comment.