Skip to content

Commit

Permalink
test: 緩存被字典強制取代前的 properties 來檢測是否有因為版本變動而修正更改內容
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Dec 5, 2022
1 parent d9da59b commit 8a0b426
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/cache-properties.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { sync as FastGlob } from '@bluelovers/fast-glob/bluebird';
import { join } from 'upath2';
import { __plugin_downloaded_dir_unzip } from '../lib/const';
import { handlePropertiesFile, LAZY_PROPERTIES, LAZY_PROPERTIES_KEYS } from '../lib/build/properties-replace';
import { DotProperties } from 'dot-properties-loader';
import { escape } from 'dot-properties2/lib/escape';

const lang = 'zh' as const
const cwd = join(__plugin_downloaded_dir_unzip, lang);

describe(`cache original properties`, () =>
{
const _map: Record<string, Record<string, string>> = {};
const _map2: Record<string, string> = {};

describe(`files`, () =>
{
FastGlob<string>([
'**/*.properties',
], {
cwd,
}).forEach(file =>
{

const fullpath = join(cwd, file);

const dp = new DotProperties({
file: fullpath,
});

const tree = dp.tree;
let _exists = false;

LAZY_PROPERTIES_KEYS
.forEach(key =>
{

if (key in tree)
{
_map[file] ??= {};

const value = dp.get(key) as string;
const value_escaped = escape(value, false);

_map[file][key] = value_escaped;
_exists = true;

if (LAZY_PROPERTIES.get(key) === value)
{
_map2[key] = value_escaped;
}
}

})
;

if (_exists)
{
test(file, () =>
{
expect(_map[file]).toMatchSnapshot();
});
}

});
});

test(`same`, () =>
{
expect(_map2).toMatchSnapshot();
});
});

0 comments on commit 8a0b426

Please sign in to comment.