Skip to content

Commit 0560c4b

Browse files
committed
update tests by removing token.raw
1 parent 3d10cb7 commit 0560c4b

File tree

44 files changed

+1095
-1024
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1095
-1024
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
"setup": "git submodule update --init && cd test/fixtures/eslint && npm install",
5858
"pretest": "run-s build lint",
5959
"test": "nyc npm run _mocha",
60+
"preupdate-fixtures": "npm run -s build",
61+
"update-fixtures": "node test/tools/update-template-ast.js",
6062
"preversion": "npm test",
6163
"version": "npm run -s build",
6264
"postversion": "git push && git push --tags",

test/ast.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ function replacer(key, value) {
5151
}
5252

5353
/**
54-
* Get information of tokens.
55-
* This uses source code text to check the ranges of tokens.
54+
* Get all tokens of the given AST.
5655
* @param {ASTNode} ast The root node of AST.
57-
* @returns {(string[])[]} Information of tokens.
56+
* @returns {Token[]} Tokens.
5857
*/
5958
function getAllTokens(ast) {
6059
const tokenArrays = [ast.tokens, ast.comments]
@@ -118,14 +117,12 @@ describe("Template AST", () => {
118117
})
119118

120119
it("should have correct range.", () => {
121-
for (const token of getAllTokens(actual.ast)) {
122-
if (token.raw === undefined) {
123-
continue
124-
}
120+
const resultPath = path.join(ROOT, `${name}/token-ranges.json`)
121+
const expectedText = fs.readFileSync(resultPath, "utf8")
122+
const tokens = getAllTokens(actual.ast).map(t => source.slice(t.range[0], t.range[1]))
123+
const actualText = JSON.stringify(tokens, null, 4)
125124

126-
const text = source.slice(token.range[0], token.range[1])
127-
assert.strictEqual(text, token.raw)
128-
}
125+
assert.strictEqual(actualText, expectedText)
129126
})
130127

131128
it("should have correct location.", () => {

0 commit comments

Comments
 (0)