Skip to content

Commit

Permalink
chore(evasive-transform): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Oct 23, 2023
1 parent 76666ca commit fa8edbb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 54 deletions.
66 changes: 21 additions & 45 deletions packages/evasive-transform/test/snapshots/test-evade-censor.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Generated by [AVA](https://avajs.dev).
var node_fs=require('node:fs');␊
/**␊
* @returns {ІᛖРΟᏒТ('node:fs').constants.F_OK}␊
* @returns {imрort('node:fs').constants.F_OK}␊
*/␊
function bambalam(){␊
return node_fs.constants.F_OK;␊
}␊
/**␊
* <!X- this should become less evil -X>␊
* <!- this should become less evil ->␊
*/␊
function monkey(){␊
return true;␊
Expand All @@ -39,14 +39,14 @@ Generated by [AVA](https://avajs.dev).
var node_fs=require('node:fs');␊
/**␊
* @returns {ІᛖРΟᏒТ('node:fs').constants.F_OK}␊
* @returns {imрort('node:fs').constants.F_OK}␊
*/␊
function bambalam(){␊
return node_fs.constants.F_OK;␊
}␊
/**␊
* <!X- this should become less evil -X>␊
* <!- this should become less evil ->␊
*/␊
function monkey(){␊
return true;␊
Expand All @@ -65,14 +65,14 @@ Generated by [AVA](https://avajs.dev).
var node_fs=require('node:fs');␊
/**␊
* @returns {ІᛖРΟᏒТ('node:fs').constants.F_OK}␊
* @returns {imрort('node:fs').constants.F_OK}␊
*/␊
function bambalam(){␊
return node_fs.constants.F_OK;␊
}␊
/**␊
* <!X- this should become less evil -X>␊
* <!- this should become less evil ->␊
*/␊
function monkey(){␊
return true;␊
Expand Down Expand Up @@ -110,14 +110,14 @@ Generated by [AVA](https://avajs.dev).
var node_fs=require('node:fs');␊
/**␊
* @returns {ІᛖРΟᏒТ('node:fs').constants.F_OK}␊
* @returns {imрort('node:fs').constants.F_OK}␊
*/␊
function bambalam(){␊
return node_fs.constants.F_OK;␊
}␊
/**␊
* <!X- this should become less evil -X>␊
* <!- this should become less evil ->␊
*/␊
function monkey(){␊
return true;␊
Expand Down Expand Up @@ -150,58 +150,34 @@ Generated by [AVA](https://avajs.dev).

> Snapshot 1
`'use strict';␊
var node_fs=require('node:fs');␊
`'use strict';var␊
/**␊
* @returns {ІᛖРΟᏒТ('node:fs').constants.F_OK}␊
node_fs=require('node:fs');/**␊
* @returns {imрort('node:fs').constants.F_OK}␊
*/␊
function bambalam(){␊
return node_fs.constants.F_OK;␊
}␊
/**␊
* <!X- this should become less evil -X>␊
*/␊
function monkey(){␊
return true;␊
}␊
exports.bambalam=bambalam;␊
exports.monkey=monkey;␊
/*# sourceMappingURL=index.cjs.map*/`
return node_fs.constants.F_OK;}/**␊
* <!‐- this should become less evil -‐>␊
*/function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/`

## evadeCensor() - successful source transform w/ source map, source URL & unmapping

> Snapshot 1
`'use strict';␊
`'use strict';var
var node_fs=require('node:fs');␊
/**␊
* @returns {ІᛖРΟᏒТ('node:fs').constants.F_OK}␊
node_fs=require('node:fs');/**␊
* @returns {imрort('node:fs').constants.F_OK}␊
*/␊
function bambalam(){␊
return node_fs.constants.F_OK;␊
}␊
/**␊
* <!X- this should become less evil -X>␊
*/␊
function monkey(){␊
return true;␊
}␊
exports.bambalam=bambalam;␊
exports.monkey=monkey;␊
/*# sourceMappingURL=index.cjs.map*/`
return node_fs.constants.F_OK;}/**␊
* <!‐- this should become less evil -‐>␊
*/function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/`

> Snapshot 2
{
mappings: 'AAAA;;AAEA,GAAIA,CAAAA,OAAO,CAAGC,OAAO,CAAC,SAAD,CAArB;;AAEA;AACA;AACA;AACA,QAASC,CAAAA,QAAT,EAAoB;AAClB,MAAOF,CAAAA,OAAO,CAACG,SAAR,CAAkBC,IAAzB;AACD;;AAED;AACA;AACA;AACA,QAASC,CAAAA,MAAT,EAAkB;AAChB,MAAO,KAAP;AACD;;AAEDC,OAAO,CAACJ,QAAR,CAAmBA,QAAnB;AACAI,OAAO,CAACD,MAAR,CAAiBA,MAAjB;AACA',
mappings: 'AAAA;;AAEAA,OAAA,CAAAC,OAAA,CAAA,SAAA,CAFA,CAEA;AACA;AACA;AACO,QAASC,CAAAA,QAAT,EAAoB;AACzB,MAAOF,CAAAA,OAAA,CAAAG,SAAA,CAAUC,IAAjB,CADyB,CAH3B;AACA;AACA,GACO,QAASC,CAAAA,MAAT,EAAkB,CACvB,MAAO,KAAP,CADuB,CAChBC,OAAA,CAAAJ,QAAA,CAAAA,QAAA,CAAAI,OAAA,CAAAD,MAAA,CAAAA,MAAA',
names: [
'node_fs',
'require',
Expand Down
Binary file modified packages/evasive-transform/test/snapshots/test-evade-censor.js.snap
Binary file not shown.
21 changes: 15 additions & 6 deletions packages/evasive-transform/test/test-evade-censor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { evadeCensor } from '../src/index.js';
import { test } from './prepare-test-env-ava.js';

/**
* Prep snapshots for cross-platform compat
* @param {string} str
* @returns {string}
*/
function dos2unix(str) {
return str.replace(/\r\n?/g, '\n');
}

test('evadeCensor() - missing "source" arg', async t => {
// @ts-expect-error - intentional missing args
await t.throwsAsync(evadeCensor());
Expand All @@ -10,7 +19,7 @@ test('evadeCensor() - successful source transform', async t => {
const { source } = t.context;
const { code, map } = await evadeCensor(source);

t.snapshot(code);
t.snapshot(dos2unix(code));
t.is(map, undefined);
});

Expand All @@ -20,7 +29,7 @@ test('evadeCensor() - successful source transform w/ source map', async t => {
sourceMap,
});

t.snapshot(code);
t.snapshot(dos2unix(code));
t.is(map, undefined);
});

Expand All @@ -31,7 +40,7 @@ test('evadeCensor() - successful source transform w/ source map & source URL', a
sourceUrl,
});

t.snapshot(code);
t.snapshot(dos2unix(code));
t.snapshot(map);
});

Expand All @@ -41,7 +50,7 @@ test('evadeCensor() - successful source transform w/ source URL', async t => {
sourceUrl,
});

t.snapshot(code);
t.snapshot(dos2unix(code));
t.snapshot(map);
});

Expand All @@ -52,7 +61,7 @@ test('evadeCensor() - successful source transform w/ source map & unmapping', as
useLocationUnmap: true,
});

t.snapshot(code);
t.snapshot(dos2unix(code));
t.is(map, undefined);
});

Expand All @@ -64,6 +73,6 @@ test('evadeCensor() - successful source transform w/ source map, source URL & un
useLocationUnmap: true,
});

t.snapshot(code);
t.snapshot(dos2unix(code));
t.snapshot(map);
});
2 changes: 1 addition & 1 deletion packages/evasive-transform/test/test-location-unmapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { parse: parseBabel } = babelParser;
test('makeLocationUnmapper() - missing source map', async t => {
// @ts-expect-error - wrong number of args
await t.throwsAsync(() => makeLocationUnmapper(), {
message: 'Invalid arguments; expected non-empty JSON string sourceMap',
message: 'Invalid arguments; expected sourceMap',
});
});

Expand Down
6 changes: 4 additions & 2 deletions packages/evasive-transform/test/test-transform-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('transformComment() - defang HTML comment', async t => {
value: '<!-- evil code -->',
});
transformComment(comment);
t.is(comment.value, '<!X- evil code -X>');
t.is(comment.value, '<!\u{2010}- evil code -\u{2010}>');
});

test('transformComment() - rewrite suspicious import(...)', async t => {
Expand All @@ -37,7 +37,9 @@ test('transformComment() - rewrite suspicious import(...)', async t => {
transformComment(comment);
t.regex(
comment.value,
new RegExp("\\* @type \\{ІᛖРΟᏒТ\\('c:\\\\My Documents\\\\user\\.js'\\)"),
new RegExp(
"\\* @type \\{im\u{440}ort\\('c:\\\\My Documents\\\\user\\.js'\\)",
),
);
});

Expand Down

0 comments on commit fa8edbb

Please sign in to comment.