stylable-intelligence icon indicating copy to clipboard operation
stylable-intelligence copied to clipboard

extract driver(s) for service tests

Open amir-arad opened this issue 6 years ago • 2 comments

currently the tests in test/lib/service.spec.ts have a lot of verbose code (boilerplate, shallow namespace, magic numbers etc. ) that can be made much more readable with relatively little effort.

the concept not necessarily the perfect API):

const {fs, fsDriver} = makeTestFs();
const fooDriver : {name, text, Document, positions} = fsDriver
.addFile('foo.bar' /* fileName*/, editorText`
    |foo${1}bar
    |${2}biz${1}${2}baz
` /* string | contentAndPositions */ , 'pseudocode' /* languageId */);
fooDriver.positions.range(1)  // returns the range between the two 1's from the template
fooDriver.positions.last(2) // returns the position of the last 2 from the template

where editorText removes pipe indentation, and computes positions (returns contentAndPositions). Document is a result of TextDocumentItem.create(...) name and text are the name and content of the file for easy reference down the test.

the test drivers themselves of course have to be tested. see test/testkit/text.spec.ts for example.

amir-arad avatar May 23 '18 06:05 amir-arad