diff --git a/.airtap.yml b/.airtap.yml index d4934b4..35548f0 100644 --- a/.airtap.yml +++ b/.airtap.yml @@ -5,13 +5,10 @@ providers: browsers: - name: chrome - name: firefox - - name: safari - version: 11 - platform: Mac 10.13 # https://github.com/airtap/sauce-browsers/issues/3 - name: safari version: 12..latest - name: ios_saf - version: 11..latest + version: 12..latest - name: chrome for android version: 6..latest - name: msedge diff --git a/test/self.js b/test/self.js index 1a6b2b7..520ea9e 100644 --- a/test/self.js +++ b/test/self.js @@ -91,6 +91,53 @@ function implement (ctor, methods) { return Test } +// Temporary test for browsers +// Not supported on Safari < 12 and Safari iOS < 12 +test('async generator', async function (t) { + let ended = false + + const end = async () => { + await new Promise((resolve) => setTimeout(resolve, 100)) + ended = true + } + + async function * generator () { + try { + yield 1 + yield 2 + yield 3 + yield 4 + } finally { + // Test that we're always able to cleanup resources + await end() + } + } + + const res = [] + + for await (const x of generator()) { + res.push(x) + if (x === 2) break + } + + t.same(res, [1, 2]) + t.is(ended, true) + + ended = false + + try { + for await (const x of generator()) { + res.push(x) + if (x === 2) throw new Error('userland error') + } + } catch (err) { + t.is(err.message, 'userland error') + } + + t.same(res, [1, 2, 1, 2]) + t.is(ended, true) +}) + /** * Extensibility */