Skip to content

Commit ccef13a

Browse files
committed
ditch async/await in tests, so that they run in node 6
1 parent 8a0813e commit ccef13a

File tree

2 files changed

+102
-100
lines changed

2 files changed

+102
-100
lines changed

test/runtime/index.js

Lines changed: 78 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("runtime", () => {
5151
throw new Error("Forgot to remove `solo: true` from test");
5252
}
5353

54-
(config.skip ? it.skip : config.solo ? it.only : it)(`${dir} (${shared ? 'shared' : 'inline'} helpers)`, async () => {
54+
(config.skip ? it.skip : config.solo ? it.only : it)(`${dir} (${shared ? 'shared' : 'inline'} helpers)`, () => {
5555
if (failed.has(dir)) {
5656
// this makes debugging easier, by only printing compiled output once
5757
throw new Error('skipping test, already failed');
@@ -105,95 +105,98 @@ describe("runtime", () => {
105105

106106
const window = env();
107107

108-
try {
109-
// set of hacks to support transition tests
110-
transitionManager.running = false;
111-
transitionManager.transitions = [];
112-
113-
const raf = {
114-
time: 0,
115-
callback: null,
116-
tick: now => {
117-
raf.time = now;
118-
if (raf.callback) raf.callback();
119-
}
120-
};
121-
window.performance = { now: () => raf.time };
122-
global.requestAnimationFrame = cb => {
123-
let called = false;
124-
raf.callback = () => {
125-
if (!called) {
126-
called = true;
127-
cb();
108+
return Promise.resolve()
109+
.then(() => {
110+
// set of hacks to support transition tests
111+
transitionManager.running = false;
112+
transitionManager.transitions = [];
113+
114+
const raf = {
115+
time: 0,
116+
callback: null,
117+
tick: now => {
118+
raf.time = now;
119+
if (raf.callback) raf.callback();
128120
}
129121
};
130-
};
131-
132-
global.window = window;
122+
window.performance = { now: () => raf.time };
123+
global.requestAnimationFrame = cb => {
124+
let called = false;
125+
raf.callback = () => {
126+
if (!called) {
127+
called = true;
128+
cb();
129+
}
130+
};
131+
};
133132

134-
try {
135-
SvelteComponent = require(`./samples/${dir}/main.html`);
136-
} catch (err) {
137-
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte); // eslint-disable-line no-console
138-
throw err;
139-
}
133+
global.window = window;
140134

141-
global.window = window;
135+
try {
136+
SvelteComponent = require(`./samples/${dir}/main.html`);
137+
} catch (err) {
138+
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte); // eslint-disable-line no-console
139+
throw err;
140+
}
142141

143-
// Put the constructor on window for testing
144-
window.SvelteComponent = SvelteComponent;
142+
global.window = window;
145143

146-
const target = window.document.querySelector("main");
144+
// Put the constructor on window for testing
145+
window.SvelteComponent = SvelteComponent;
147146

148-
const warnings = [];
149-
const warn = console.warn;
150-
console.warn = warning => {
151-
warnings.push(warning);
152-
};
147+
const target = window.document.querySelector("main");
153148

154-
const options = Object.assign({}, {
155-
target,
156-
hydrate,
157-
data: config.data
158-
}, config.options || {});
149+
const warnings = [];
150+
const warn = console.warn;
151+
console.warn = warning => {
152+
warnings.push(warning);
153+
};
159154

160-
const component = new SvelteComponent(options);
155+
const options = Object.assign({}, {
156+
target,
157+
hydrate,
158+
data: config.data
159+
}, config.options || {});
161160

162-
console.warn = warn;
161+
const component = new SvelteComponent(options);
163162

164-
if (config.error) {
165-
unintendedError = true;
166-
throw new Error("Expected a runtime error");
167-
}
163+
console.warn = warn;
168164

169-
if (config.warnings) {
170-
assert.deepEqual(warnings, config.warnings);
171-
} else if (warnings.length) {
172-
unintendedError = true;
173-
throw new Error("Received unexpected warnings");
174-
}
165+
if (config.error) {
166+
unintendedError = true;
167+
throw new Error("Expected a runtime error");
168+
}
175169

176-
if (config.html) {
177-
assert.htmlEqual(target.innerHTML, config.html);
178-
}
170+
if (config.warnings) {
171+
assert.deepEqual(warnings, config.warnings);
172+
} else if (warnings.length) {
173+
unintendedError = true;
174+
throw new Error("Received unexpected warnings");
175+
}
179176

180-
if (config.test) {
181-
await config.test(assert, component, target, window, raf);
182-
} else {
183-
component.destroy();
184-
assert.equal(target.innerHTML, "");
185-
}
186-
} catch (err) {
187-
if (config.error && !unintendedError) {
188-
config.error(assert, err);
189-
} else {
190-
failed.add(dir);
191-
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte); // eslint-disable-line no-console
192-
throw err;
193-
}
194-
}
177+
if (config.html) {
178+
assert.htmlEqual(target.innerHTML, config.html);
179+
}
195180

196-
if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte);
181+
if (config.test) {
182+
return config.test(assert, component, target, window, raf);
183+
} else {
184+
component.destroy();
185+
assert.equal(target.innerHTML, "");
186+
}
187+
})
188+
.catch(err => {
189+
if (config.error && !unintendedError) {
190+
config.error(assert, err);
191+
} else {
192+
failed.add(dir);
193+
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte); // eslint-disable-line no-console
194+
throw err;
195+
}
196+
})
197+
.then(() => {
198+
if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate }, svelte);
199+
});
197200
});
198201
}
199202

test/runtime/samples/await-then-catch/_config.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,37 @@ export default {
1313
<p>loading...</p>
1414
`,
1515

16-
async test(assert, component, target) {
16+
test(assert, component, target) {
1717
fulfil(42);
18-
await thePromise;
1918

20-
assert.htmlEqual(target.innerHTML, `
21-
<p>the value is 42</p>
22-
`);
19+
return thePromise
20+
.then(() => {
21+
assert.htmlEqual(target.innerHTML, `
22+
<p>the value is 42</p>
23+
`);
2324

24-
let reject;
25+
let reject;
2526

26-
thePromise = new Promise((f, r) => {
27-
reject = r;
28-
});
27+
thePromise = new Promise((f, r) => {
28+
reject = r;
29+
});
2930

30-
component.set({
31-
thePromise
32-
});
31+
component.set({
32+
thePromise
33+
});
3334

34-
assert.htmlEqual(target.innerHTML, `
35-
<p>loading...</p>
36-
`);
35+
assert.htmlEqual(target.innerHTML, `
36+
<p>loading...</p>
37+
`);
3738

38-
reject(new Error('something broke'));
39+
reject(new Error('something broke'));
3940

40-
try {
41-
await thePromise;
42-
} catch (err) {
43-
// do nothing
44-
}
45-
46-
assert.htmlEqual(target.innerHTML, `
47-
<p>oh no! something broke</p>
48-
`);
41+
return thePromise.catch(() => {});
42+
})
43+
.then(() => {
44+
assert.htmlEqual(target.innerHTML, `
45+
<p>oh no! something broke</p>
46+
`);
47+
});
4948
}
5049
};

0 commit comments

Comments
 (0)