Skip to content

Commit

Permalink
Convert co to async await
Browse files Browse the repository at this point in the history
  • Loading branch information
xg-wang committed Mar 29, 2020
1 parent 9ccabaf commit 87888f4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 74 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"broccoli-test-helper": "^2.0.0",
"chai": "^4.1.2",
"chai-fs": "^2.0.0",
"co": "^4.6.0",
"ember-cli": "~3.9.0",
"ember-cli-addon-tests": "^0.11.1",
"ember-cli-dependency-checker": "^3.2.0",
Expand Down
61 changes: 30 additions & 31 deletions test/browsers-target-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const AddonFactory = require('../');
const expect = require('chai').expect;
const helpers = require('broccoli-test-helper');
const co = require('co');

describe(`Do not include the polyfill if the browser targets match`, function() {
let output, subject, addon;
Expand All @@ -26,18 +25,18 @@ describe(`Do not include the polyfill if the browser targets match`, function()
output = helpers.createBuilder(subject);
});

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

it('fetch & AbortController polyfills are not included', co.wrap(function* () {
yield output.build();
it('fetch & AbortController polyfills are not included', async function () {
await output.build();
let files = output.read();
expect(files).to.have.all.keys('ember-fetch.js');
expect(files['ember-fetch.js']).to.include(`var preferNative = true`);
expect(files['ember-fetch.js']).to.not.include(`fetch.polyfill = true`);
expect(files['ember-fetch.js']).to.not.include(`class AbortController`);
}));
});

});

Expand All @@ -62,18 +61,18 @@ describe(`Ignore target browsers if preferNative is false`, function() {
output = helpers.createBuilder(subject);
});

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

it('fetch & AbortController polyfills are included', co.wrap(function* () {
yield output.build();
it('fetch & AbortController polyfills are included', async function () {
await output.build();
let files = output.read();
expect(files).to.have.all.keys('ember-fetch.js');
expect(files['ember-fetch.js']).to.include(`var preferNative = false`);
expect(files['ember-fetch.js']).to.include(`fetch.polyfill = true`);
expect(files['ember-fetch.js']).to.include(`class AbortController`);
}));
});

});

Expand All @@ -98,18 +97,18 @@ describe(`Include the polyfill if the browser targets do not match`, function()
output = helpers.createBuilder(subject);
});

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

it('fetch & AbortController polyfills are included', co.wrap(function* () {
yield output.build();
it('fetch & AbortController polyfills are included', async function () {
await output.build();
let files = output.read();
expect(files).to.have.all.keys('ember-fetch.js');
expect(files['ember-fetch.js']).to.include(`var preferNative = true`);
expect(files['ember-fetch.js']).to.include(`fetch.polyfill = true`);
expect(files['ember-fetch.js']).to.include(`class AbortController`);
}));
});

});

Expand All @@ -134,18 +133,18 @@ describe(`Include the abortcontroller polyfill only if the browser targets suppo
output = helpers.createBuilder(subject);
});

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

it('AbortController polyfill is included', co.wrap(function* () {
yield output.build();
it('AbortController polyfill is included', async function () {
await output.build();
let files = output.read();
expect(files).to.have.all.keys('ember-fetch.js');
expect(files['ember-fetch.js']).to.include(`var preferNative = true`);
expect(files['ember-fetch.js']).to.not.include(`fetch.polyfill = true`);
expect(files['ember-fetch.js']).to.include(`class AbortController`);
}));
});

});

Expand All @@ -170,17 +169,17 @@ describe(`Include the polyfill if alwaysIncludePolyfill=true`, function() {
output = helpers.createBuilder(subject);
});

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

it('fetch & AbortController polyfills are included', co.wrap(function* () {
yield output.build();
it('fetch & AbortController polyfills are included', async function () {
await output.build();
let files = output.read();
expect(files).to.have.all.keys('ember-fetch.js');
expect(files['ember-fetch.js']).to.include(`var preferNative = true`);
expect(files['ember-fetch.js']).to.include(`fetch.polyfill = true`);
expect(files['ember-fetch.js']).to.include(`class AbortController`);
}));
});

});
73 changes: 36 additions & 37 deletions test/prefer-native-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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 Down Expand Up @@ -34,21 +33,21 @@ require('fetch-test');
output = helpers.createBuilder(subject);
});

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

it('preferNative is built into vendor file', co.wrap(function*() {
yield output.build();
it('preferNative is built into vendor file', async function () {
await 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`, co.wrap(function*() {
yield output.build();
} native fetch as specified`, async function () {
await output.build();
let emberFetchCode = output.read()['ember-fetch.js'];
const amdLoaderCode = fs.readFileSync(require.resolve('loader.js'));
const sandbox = {
Expand All @@ -64,11 +63,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', co.wrap(function*() {
yield output.build();
it('Has fetch poly fill even if fetch is not there', async function () {
await output.build();
let emberFetchCode = output.read()['ember-fetch.js'];
const amdLoaderCode = fs.readFileSync(require.resolve('loader.js'));
const sandbox = {
Expand All @@ -92,7 +91,7 @@ require('fetch-test');
const code = amdLoaderCode + emberFetchCode + testCodeForNonFetch;
vm.runInContext(code, sandbox);
expect(sandbox.window.__result).to.equal(true);
}))
})
}
});

Expand Down Expand Up @@ -121,21 +120,21 @@ require('fetch-test');
output = helpers.createBuilder(subject);
});

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

it('preferNative is built into vendor file', co.wrap(function*() {
yield output.build();
it('preferNative is built into vendor file', async function () {
await 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`, co.wrap(function*() {
yield output.build();
} native fetch as specified`, async function () {
await output.build();
let emberFetchCode = output.read()['ember-fetch.js'];
const amdLoaderCode = fs.readFileSync(require.resolve('loader.js'));
const sandbox = {
Expand All @@ -151,11 +150,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', co.wrap(function*() {
yield output.build();
it('Has fetch poly fill even if fetch is not there', async function () {
await output.build();
let emberFetchCode = output.read()['ember-fetch.js'];
const amdLoaderCode = fs.readFileSync(require.resolve('loader.js'));
const sandbox = {
Expand All @@ -179,7 +178,7 @@ require('fetch-test');
const code = amdLoaderCode + emberFetchCode + testCodeForNonFetch;
vm.runInContext(code, sandbox);
expect(sandbox.window.__result).to.equal(true);
}))
})
}
});

Expand Down Expand Up @@ -212,21 +211,21 @@ require('fetch-test');
output = helpers.createBuilder(subject);
});

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

it('preferNative is built into vendor file', co.wrap(function*() {
yield output.build();
it('preferNative is built into vendor file', async function () {
await 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`, co.wrap(function*() {
yield output.build();
} native fetch as specified`, async function () {
await output.build();
let emberFetchCode = output.read()['ember-fetch.js'];
const amdLoaderCode = fs.readFileSync(require.resolve('loader.js'));
const sandbox = {
Expand All @@ -242,11 +241,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', co.wrap(function*() {
yield output.build();
it('Has fetch poly fill even if fetch is not there', async function () {
await output.build();
let emberFetchCode = output.read()['ember-fetch.js'];
const amdLoaderCode = fs.readFileSync(require.resolve('loader.js'));
const sandbox = {
Expand All @@ -270,7 +269,7 @@ require('fetch-test');
const code = amdLoaderCode + emberFetchCode + testCodeForNonFetch;
vm.runInContext(code, sandbox);
expect(sandbox.window.__result).to.equal(true);
}))
})
}
});
});
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3844,11 +3844,6 @@ clone@^2.0.0, clone@^2.1.2:
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
integrity sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=

co@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
integrity sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=

code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
Expand Down

0 comments on commit 87888f4

Please sign in to comment.