Skip to content

Commit

Permalink
chore: fix @formatjs/icu-messageformat-parser test
Browse files Browse the repository at this point in the history
  • Loading branch information
long.ho committed Sep 6, 2022
1 parent 16c943c commit 2b26b36
Show file tree
Hide file tree
Showing 112 changed files with 96 additions and 67 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bazel-out

packages/babel-plugin-formatjs/integration-tests/node_modules
packages/ts-transformer/integration-tests/node_modules
packages/icu-messageformat-parser/integration-tests/node_modules
packages/cli/integration-tests/node_modules
packages/react-intl/examples/node_modules
packages/babel-plugin-formatjs/node_modules
Expand Down
13 changes: 0 additions & 13 deletions packages/icu-messageformat-parser-tests/BUILD

This file was deleted.

2 changes: 2 additions & 0 deletions packages/icu-messageformat-parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ export function parse(message: string, opts: ParserOptions = {}) {
return result.val
}
export * from './types'
// only for testing
export const _Parser = Parser
36 changes: 36 additions & 0 deletions packages/icu-messageformat-parser/integration-tests/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("//tools:index.bzl", "generate_src_file")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

TEST_CASES = glob(["test_cases/*"])

# [ts_script(
# name = "gen_parser_test_%s" % f.split("/")[-1],
# outs = ["%s.tmp" % f.split("/")[-1]],
# args = [
# "--input",
# f
# ],
# data = [
# ":node_modules/@formatjs/icu-messageformat-parser",
# "//:node_modules/lodash",
# f
# ],
# entry_point = "run-parser.ts",
# ) for f in TEST_CASES]

[generate_src_file(
name = "gen_parser_test_%s" % f.split("/")[-1],
src = f,
data = [
":node_modules/@formatjs/icu-messageformat-parser",
"//:node_modules/lodash",
f
],
args = [
"--input %s/%s" % (package_name(),f),
],
entry_point = "run-parser.ts",
) for f in TEST_CASES]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@formatjs/icu-messageformat-parser": "workspace:*"
}
}
38 changes: 38 additions & 0 deletions packages/icu-messageformat-parser/integration-tests/run-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {_Parser} from '@formatjs/icu-messageformat-parser'
import fs from 'fs'
import minimist from 'minimist'

interface Args extends minimist.ParsedArgs {
input: string
out: string
}

function run({input, out}: Args) {
console.log(__dirname)
const sections = fs.readFileSync(input, 'utf-8').split('\n---\n')
const message = sections[0]
const snapshotOptions = JSON.parse(sections[1])
const options = {...snapshotOptions}
// Note: allow locale to be specified via an identifier.
if (options.locale) {
options.locale = new Intl.Locale(options.locale)
}

const parsed = new _Parser(message, options).parse()

// If the mismatch is intentional, use `UPDATE_SNAPSHOT=1` env var
// with bazel run to update the snapshot.
fs.writeFileSync(
out,
[
message,
JSON.stringify(snapshotOptions, null, 2),
JSON.stringify(parsed, null, 2),
].join('\n---\n'),
'utf-8'
)
}

if (require.main === module) {
run(minimist<Args>(process.argv.slice(2)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
}
],
"err": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
}
],
"err": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
}
],
"err": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
}
],
"err": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
}
],
"err": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
}
],
"err": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
}
],
"err": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
}
],
"err": null
}
}
46 changes: 0 additions & 46 deletions packages/icu-messageformat-parser/tests/parser.test.ts

This file was deleted.

6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b26b36

Please sign in to comment.