Skip to content

Commit b5f9c82

Browse files
authored
Avoid destructuring plugin methods in tests (#161)
1 parent 447b84f commit b5f9c82

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

test/index.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,56 @@ const sander = require('sander');
99
const plugin = require('..');
1010

1111
test('resolves using pkg.svelte', () => {
12-
const { resolveId } = plugin();
12+
const p = plugin();
1313
assert.is(
14-
resolveId('widget', path.resolve('test/foo/main.js')),
14+
p.resolveId('widget', path.resolve('test/foo/main.js')),
1515
path.resolve('test/node_modules/widget/src/Widget.svelte')
1616
);
1717
});
1818

1919
test('ignores built-in modules', () => {
20-
const { resolveId } = plugin();
20+
const p = plugin();
2121
assert.ok(
22-
resolveId('path', path.resolve('test/foo/main.js')) == null
22+
p.resolveId('path', path.resolve('test/foo/main.js')) == null
2323
);
2424
});
2525

2626
test('ignores esm modules that do not export package.json', () => {
27-
const { resolveId } = plugin();
27+
const p = plugin();
2828
assert.ok(
29-
resolveId('esm-no-pkg-export', path.resolve('test/foo/main.js')) == null
29+
p.resolveId('esm-no-pkg-export', path.resolve('test/foo/main.js')) == null
3030
);
3131
});
3232

3333
test('resolves esm module that exports package.json', () => {
34-
const { resolveId } = plugin();
34+
const p = plugin();
3535
assert.is(
36-
resolveId('esm-component', path.resolve('test/foo/main.js')),
36+
p.resolveId('esm-component', path.resolve('test/foo/main.js')),
3737
path.resolve('test/node_modules/esm-component/src/Component.svelte')
3838
);
3939
});
4040

4141
test('ignores virtual modules', () => {
42-
const { resolveId } = plugin();
42+
const p = plugin();
4343
assert.ok(
44-
resolveId('path', path.resolve('\0some-plugin-generated-module')) == null
44+
p.resolveId('path', path.resolve('\0some-plugin-generated-module')) == null
4545
);
4646
});
4747

4848
test('supports component name assignment', async () => {
49-
const { transform } = plugin();
50-
const index = await transform('', 'index.svelte');
49+
const p = plugin();
50+
const index = await p.transform('', 'index.svelte');
5151

5252
assert.is.not(index.code.indexOf('class Index extends SvelteComponent'), -1);
5353

54-
const card = await transform('', 'card/index.svelte');
54+
const card = await p.transform('', 'card/index.svelte');
5555
assert.is(card.code.indexOf('class Index extends SvelteComponent'), -1);
5656
assert.is.not(card.code.indexOf('class Card extends SvelteComponent'), -1);
5757
});
5858

5959
test('creates a {code, map, dependencies} object, excluding the AST etc', async () => {
60-
const { transform } = plugin();
61-
const compiled = await transform('', 'test.svelte');
60+
const p = plugin();
61+
const compiled = await p.transform('', 'test.svelte');
6262
assert.equal(Object.keys(compiled), ['code', 'map', 'dependencies']);
6363
});
6464

@@ -91,11 +91,11 @@ test('respects `sourcemapExcludeSources` Rollup option', async () => {
9191
});
9292

9393
test('squelches "unused CSS" warnings if `emitCss: false`', () => {
94-
const { transform } = plugin({
94+
const p = plugin({
9595
emitCss: false
9696
});
9797

98-
transform.call({
98+
p.transform.call({
9999
warn: warning => {
100100
throw new Error(warning.message);
101101
}
@@ -110,7 +110,7 @@ test('squelches "unused CSS" warnings if `emitCss: false`', () => {
110110
});
111111

112112
test('preprocesses components', async () => {
113-
const { transform } = plugin({
113+
const p = plugin({
114114
preprocess: {
115115
markup: ({ content, filename }) => {
116116
return {
@@ -124,7 +124,7 @@ test('preprocesses components', async () => {
124124
}
125125
});
126126

127-
const { code, dependencies } = await transform(`
127+
const { code, dependencies } = await p.transform(`
128128
<h1>Hello __REPLACEME__!</h1>
129129
<h2>file: __FILENAME__</h2>
130130
<style>h1 { color: red; }</style>
@@ -136,9 +136,9 @@ test('preprocesses components', async () => {
136136
});
137137

138138
test('emits a CSS file', async () => {
139-
const { load, transform } = plugin();
139+
const p = plugin();
140140

141-
const transformed = await transform(`<h1>Hello!</h1>
141+
const transformed = await p.transform(`<h1>Hello!</h1>
142142
143143
<style>
144144
h1 {
@@ -148,7 +148,7 @@ test('emits a CSS file', async () => {
148148

149149
assert.ok(transformed.code.indexOf(`import "path/to/Input.css";`) !== -1);
150150

151-
const css = load('path/to/Input.css');
151+
const css = p.load('path/to/Input.css');
152152

153153
const smc = await new SourceMapConsumer(css.map);
154154

@@ -163,9 +163,9 @@ test('emits a CSS file', async () => {
163163
});
164164

165165
test('properly escapes CSS paths', async () => {
166-
const { load, transform } = plugin();
166+
const p = plugin();
167167

168-
const transformed = await transform(`<h1>Hello!</h1>
168+
const transformed = await p.transform(`<h1>Hello!</h1>
169169
170170
<style>
171171
h1 {
@@ -175,7 +175,7 @@ test('properly escapes CSS paths', async () => {
175175

176176
assert.ok(transformed.code.indexOf(`import "path\\\\t'o\\\\Input.css";`) !== -1);
177177

178-
const css = load(`path\\t'o\\Input.css`);
178+
const css = p.load(`path\\t'o\\Input.css`);
179179

180180
const smc = await new SourceMapConsumer(css.map);
181181

@@ -193,7 +193,7 @@ test('intercepts warnings', async () => {
193193
const warnings = [];
194194
const handled = [];
195195

196-
const { transform } = plugin({
196+
const p = plugin({
197197
onwarn(warning, handler) {
198198
warnings.push(warning);
199199

@@ -203,7 +203,7 @@ test('intercepts warnings', async () => {
203203
}
204204
});
205205

206-
await transform.call({
206+
await p.transform.call({
207207
warn: warning => {
208208
handled.push(warning);
209209
}

0 commit comments

Comments
 (0)