Skip to content

Commit

Permalink
simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetTechuila committed Jan 30, 2025
1 parent cf0662e commit 019e044
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions src/test/suite/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import * as assert from 'assert'
import * as os from 'os'
import {
Position,
window,
workspace,
WorkspaceEdit,
Selection,
TextDocument,
} from 'vscode'
import { Position, window, workspace, WorkspaceEdit, Selection } from 'vscode'
import { getFixturePath, getOptionsForFixture, wait } from '../testUtils'

import * as utils from 'vscode-test-utils'
Expand Down Expand Up @@ -293,15 +286,11 @@ suite('EditorConfig extension', function () {
})

test('keep selection on format', async () => {
const obj = withSetting('insert_final_newline', 'true')
await obj.createDoc('bar')
await withSetting('insert_final_newline', 'true').saveText('foobar')
assert(window.activeTextEditor, 'no active editor')

const position = new Position(0, 3)
const position = new Position(0, 0)
const selection = new Selection(position, position)
window.activeTextEditor.selection = selection

await obj.saveText('foo')

assert.strictEqual(
window.activeTextEditor.selection.start.line,
Expand All @@ -323,12 +312,13 @@ function withSetting(
contents?: string
} = {},
) {
let doc: TextDocument | undefined
return {
doc,
async getText() {
return (await createDoc(options.contents)).getText()
},
saveText(text: string) {
return new Promise<string>(async resolve => {
const doc = this.doc ?? (await this.createDoc(options.contents))
const doc = await createDoc(options.contents)
workspace.onDidChangeTextDocument(doc.save)
workspace.onDidSaveTextDocument(savedDoc => {
assert.strictEqual(savedDoc.isDirty, false, 'dirty saved doc')
Expand All @@ -343,16 +333,15 @@ function withSetting(
)
})
},
async createDoc(contents = '') {
const uri = await utils.createFile(
contents,
getFixturePath([rule, value, Math.random().toString(36)]),
)
const doc = await workspace.openTextDocument(uri)
this.doc = doc
await window.showTextDocument(doc)
await wait(50) // wait for EditorConfig to apply new settings
return doc
},
}
async function createDoc(contents = '') {
const uri = await utils.createFile(
contents,
getFixturePath([rule, value, Math.random().toString(36)]),
)
const doc = await workspace.openTextDocument(uri)
await window.showTextDocument(doc)
await wait(50) // wait for EditorConfig to apply new settings
return doc
}
}

0 comments on commit 019e044

Please sign in to comment.