From 2ca8fb91c7484a83472d59025db593bfb168b209 Mon Sep 17 00:00:00 2001 From: yaochang Date: Wed, 6 Apr 2022 13:27:29 +0800 Subject: [PATCH] test: rm snapshots --- test/__snapshots__/index.test.ts.snap | 486 -------------------------- test/index.test.ts | 2 +- 2 files changed, 1 insertion(+), 487 deletions(-) delete mode 100644 test/__snapshots__/index.test.ts.snap diff --git a/test/__snapshots__/index.test.ts.snap b/test/__snapshots__/index.test.ts.snap deleted file mode 100644 index ef823c1..0000000 --- a/test/__snapshots__/index.test.ts.snap +++ /dev/null @@ -1,486 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`name module on style tag 1`] = ` -"const sanSSRHelpers = (function (exports) { - \\"use strict\\"; - /** - * 该文件可能会以字符串形式直接输出到产物中 - * 因此不能引用外部模块,会因找不到外部模块报错 - */ - Object.defineProperty(exports, \\"__esModule\\", { value: true }); - exports._ = void 0; - const BASE_PROPS = { - class: 1, - style: 1, - id: 1 - }; - const HTML_ENTITY = { - '<': '<', - '>': '>', - '\\"': '"', - \\"'\\": ''', - '\\\\u00a0': ' ', - '\\\\u2003': ' ', - '\\\\u2002': ' ', - '\\\\u2009': ' ', - '\\\\xa9': '©', - '\\\\xae': '®', - '\\\\u200c': '‌', - '\\\\u200d': '‍', - '&': '&' - }; - const rENTITY = new RegExp(\`[\${Object.keys(HTML_ENTITY).join('')}]\`, 'g'); - function escapeHTML(source) { - if (typeof source === 'string') { - return source.replace(rENTITY, (c) => HTML_ENTITY[c]); - } - return source; - } - function isObject(source) { - return typeof source === 'object' && source !== null; - } - function isArray(source) { - return source && source instanceof Array; - } - function output(value, needEscape) { - if (value == null || value === '') - return ''; - value = String(value); - return needEscape ? escapeHTML(value) : value; - } - function classFilter(source) { - if (!isArray(source)) - source = [source]; - return source.filter(x => x != null).join(' '); - } - function styleFilter(source) { - if (isObject(source)) { - return Object.keys(source) - .map(key => key + ':' + source[key] + ';') - .join(''); - } - return source; - } - function xclassFilter(inherits, own) { - if (!isArray(inherits)) - inherits = [inherits]; - const inheritStr = inherits = inherits.filter(x => x != null).join(' '); - if (inheritStr) { - if (own) - return own + ' ' + inheritStr; - return inheritStr; - } - return own; - } - function xstyleFilter(inherits, own) { - inherits = inherits && styleFilter(inherits); - if (inherits) { - if (own) - return own + ';' + inherits; - return inherits; - } - return own; - } - function attrFilter(name, value, needEscape) { - // style/class/id 值为 falsy 时不输出属性 - if (value == null || (!value && BASE_PROPS[name])) { - return ''; - } - value = String(value); - return \` \${name}=\\"\${needEscape ? escapeHTML(value) : value}\\"\`; - } - function boolAttrFilter(name, value) { - return value ? ' ' + name : ''; - } - function callFilter(ctx, name, ...args) { - let value; - try { - value = ctx.instance.filters[name].call(ctx.instance, ...args); - } - catch (e) { - /* istanbul ignore next */ - handleError(e, ctx.instance, 'filter:' + name); - } - return value; - } - function callComputed(ctx, name) { - let value; - try { - value = ctx.instance.computed[name].apply(ctx.instance); - } - catch (e) { - /* istanbul ignore next */ - handleError(e, ctx.instance, 'computed:' + name); - } - return value; - } - function iterate(val) { - return isArray(val) ? val.entries() : Object.entries(val); - } - function createFromPrototype(proto) { - function Creator() { } - Creator.prototype = proto; - return new Creator(); - } - function createInstanceFromClass(Clazz) { - // method - // compiled inited initData - const inited = Clazz.prototype.inited; - delete Clazz.prototype.inited; - const initData = Clazz.prototype.initData; - delete Clazz.prototype.initData; - // property - // template filters components computed trimWhitespace delimiters - const template = Clazz.template || Clazz.prototype.template; - const components = Clazz.components || Clazz.prototype.components; - delete Clazz.components; - delete Clazz.prototype.components; - const computed = Clazz.computed || Clazz.prototype.computed; - delete Clazz.computed; - delete Clazz.prototype.computed; - Clazz.prototype.template = '
'; - const instance = new Clazz(); - if (inited) - Clazz.prototype.inited = inited; - if (initData) - Clazz.prototype.initData = initData; - if (components) - Clazz.prototype.components = components; - Clazz.prototype.template = template; - if (computed) - instance['computed'] = Clazz.prototype.computed = Clazz.computed = computed; - return instance; - } - function getRootCtx(ctx) { - let last = ctx; - while (ctx.parentCtx) { - last = ctx; - ctx = ctx.parentCtx; - } - // 如果跟组件 render 调用的时候传递了 parentCtx,会找到这个对象 - // 通过 ctx 是否有 data 来判断是不是真正的 rootCtx - // @ts-ignore - return ctx.data ? ctx : last; - } - function handleError(e, instance, info) { - let current = instance; - while (current) { - if (typeof current.error === 'function') { - current.error(e, instance, info); - return; - } - current = current.parentComponent; - } - throw e; - } - function mergeChildSlots(childSlots) { - const sourceSlots = { - named: {}, - noname: false - }; - Object.keys(childSlots).forEach(key => { - if (key === '') { - sourceSlots.noname = true; - return; - } - sourceSlots.named[key] = true; - }); - return sourceSlots; - } - exports._ = { - output, - createInstanceFromClass, - escapeHTML, - boolAttrFilter, - attrFilter, - classFilter, - styleFilter, - xstyleFilter, - xclassFilter, - createFromPrototype, - getRootCtx, - iterate, - callFilter, - callComputed, - handleError, - mergeChildSlots - }; - //# sourceMappingURL=underscore.js.map - - \\"use strict\\"; - Object.defineProperty(exports, \\"__esModule\\", { value: true }); - exports.SanSSRData = void 0; - /** - * SSR 期间的 Data 实现,替代 import('san').SanSSRData - * - * * 不涉及视图更新 - * * 便于编译期优化 - */ - class SanSSRData { - constructor(data, instance) { - this.data = data; - this.computed = instance.computed || {}; - } - get(path) { - if (arguments.length === 0) - return this.data; - if (this.computed[path]) - return this.computed[path].call({ data: this }); - return this.parseExpr(path).reduce((val, name) => val == null ? val : val[name], this.data); - } - set(path, value) { - const seq = this.parseExpr(path); - let parent = this.data; - for (let i = 0; i < seq.length - 1; i++) { - const name = seq[i]; - if (parent[name]) { - parent = parent[name]; - } - else { - return null; - } - } - parent[seq.pop()] = value; - return value; - } - removeAt(path, index) { - const value = this.get(path); - if (value && value.splice) - value.splice(index, 1); - } - parseExpr(expr) { - return expr.split('.'); - } - } - exports.SanSSRData = SanSSRData; - //# sourceMappingURL=san-ssr-data.js.map - - \\"use strict\\"; - Object.defineProperty(exports, \\"__esModule\\", { value: true }); - exports.createResolver = void 0; - function createResolver(exports, require) { - return { - getRenderer: function ({ id, specifier = '.' }, tagName, context) { - const customSSRFilePath = context && context.customSSRFilePath; - let mod; - if (specifier === '.') { - mod = exports; - } - else { - let path; - if (customSSRFilePath) { - path = customSSRFilePath({ id, specifier, tagName }); - } - mod = require(path || specifier); - } - return mod.sanSSRRenders[id]; - }, - getChildComponentClass: function ({ id, specifier = '.' }, instance, tagName, context) { - var _a, _b; - const customComponentFilePath = context && context.customComponentFilePath; - if (customComponentFilePath && specifier !== '.') { - const path = customComponentFilePath({ id, specifier, tagName }); - if (typeof path === 'string') - return id === 'default' ? require(path) : require(path)[id]; - // 可以直接返回一个组件类 - else if (typeof path === 'function') - return path; - } - const components = instance.components || (instance.prototype && instance.prototype.components); - const ChildComponentClassOrInstance = components && components[tagName]; - if (!ChildComponentClassOrInstance) { - throw Error(\`child component is not fount: \${tagName}\${((_a = instance.prototype) === null || _a === void 0 ? void 0 : _a.id) || ''}\`); - } - if (typeof ChildComponentClassOrInstance === 'string' && ChildComponentClassOrInstance === 'self') { - return instance; - } - // component loader - if (Object.prototype.hasOwnProperty.call(ChildComponentClassOrInstance, 'load') && - Object.prototype.hasOwnProperty.call(ChildComponentClassOrInstance, 'placeholder')) { - return ChildComponentClassOrInstance.placeholder; - } - if (typeof ChildComponentClassOrInstance !== 'function' && typeof ChildComponentClassOrInstance !== 'object') { - throw Error(\`external component is not provided: \${tagName}\${((_b = instance.prototype) === null || _b === void 0 ? void 0 : _b.id) || ''}\`); - } - return ChildComponentClassOrInstance; - }, - setRenderer: function (id, fn) { - exports.sanSSRRenders = exports.sanSSRRenders || {}; - exports.sanSSRRenders[id] = fn; - }, - getPrototype: function (id) { - return this['prototypes'][id]; - }, - setPrototype: function (id, proto) { - this['prototypes'][id] = proto; - }, - prototypes: {} - }; - } - exports.createResolver = createResolver; - //# sourceMappingURL=resolver.js.map - - return exports; -})({}); -const sanSSRResolver = sanSSRHelpers.createResolver(exports, require); -\\"use strict\\"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== \\"function\\" && b !== null) - throw new TypeError(\\"Class extends value \\" + String(b) + \\" is not a constructor or null\\"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -var san_1 = require(\\"san\\"); -var ResultComponent = /** @class */ (function (_super) { - __extends(ResultComponent, _super); - function ResultComponent() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.template = \\"\\\\n
\\\\n

\\\\n \\\\n {{ title | hilight:2 | raw }}\\\\n \\\\n \\\\n 官方\\\\n \\\\n

\\\\n
\\\\n \\\\n {{ showUrl }}asdasdasd\\\\n \\\\n
\\\\n \\\\n \\\\n \\\\n
\\\\n  - \\\\n \\\\n {{ kbShowStyle }}\\\\n \\\\n \\\\n
\\\\n

\\\\n 由于该网站的robots.txt文件存在限制指令(限制搜索引擎抓取),系统无法提供该页面的内容描述 - \\\\n \\\\n 了解详情\\\\n \\\\n

\\\\n
\\\\n\\"; - return _this; - } - ResultComponent.prototype.initData = function () { - return { - officialFlag: false, - title: '', - titleUrl: '', - extQuery: '', - kbShowStyle: '', - kbUrl: '', - kbFrom: '', - showUrl: '', - toolsId: '', - robotsUrl: '', - classicInfo: [] - }; - }; - ResultComponent.prototype.inited = function () { - var str = 'se_st_robots inited'; - console.log(str); - }; - ResultComponent.prototype.created = function () { - console.log('se_st_robots created'); - }; - ResultComponent.prototype.attached = function () { - console.log('se_st_robots attached'); - }; - ResultComponent.prototype.detached = function () { - console.log('se_st_robots detached'); - }; - return ResultComponent; -}(san_1.Component)); -exports.default = ResultComponent; -sanSSRResolver.setPrototype(\\"default\\", sanSSRHelpers._.createInstanceFromClass(ResultComponent)); -sanSSRResolver.setRenderer(\\"default\\", function (data, info = {}) { - let noDataOutput = info.noDataOutput == null ? false : info.noDataOutput - let parentCtx = info.parentCtx == null ? null : info.parentCtx - let tagName = info.tagName == null ? \\"div\\" : info.tagName - let slots = info.slots == null ? {} : info.slots - const _ = sanSSRHelpers._; - const SanSSRData = sanSSRHelpers.SanSSRData; - let instance = _.createFromPrototype(sanSSRResolver.getPrototype(\\"default\\")); - instance.data = new SanSSRData(data, instance); - instance.sourceSlots = _.mergeChildSlots(slots); - instance.lifeCycle = {compiled: true, inited: false}; - if (parentCtx) { - instance.parentComponent = parentCtx.instance; - } - let refs = {} - let ctx = {instance, slots, data, parentCtx, refs, context: parentCtx && parentCtx.context} - let initData - try { - initData = instance.initData(); - } - catch (e) { - _.handleError(e, instance, \\"initData\\"); - } - if (null == initData) { - initData = {}; - } - for (let [key, value] of _.iterate(initData)) { - ctx.data[key] = ctx.data[key] !== undefined ? ctx.data[key] : value; - } - try { - instance.inited(); - } - catch (e) { - _.handleError(e, instance, \\"hook:inited\\"); - } - instance.lifeCycle.inited = true; - let html = \\"\\" - parentCtx = ctx; - html += \\"\\"; - if (!noDataOutput) { - html += \\"\\"; - } - html += \\"\\\\n

\\\\n \\"; - html += \\"\\\\n \\" + _.output(_.callFilter(ctx, \\"hilight\\", ctx.data.title), true) + \\"\\\\n \\"; - html += \\"\\\\n \\"; - if (ctx.data.officialFlag) { - html += \\"\\\\n 官方\\\\n \\"; - } - html += \\"\\\\n

\\\\n
\\\\n \\"; - html += \\"\\\\n \\" + _.output(ctx.data.showUrl, true) + \\"asdasdasd\\\\n \\"; - html += \\"\\\\n
\\\\n \\\\n \\\\n \\\\n
\\\\n \\"; - if (ctx.data.kbShowStyle) { - html += \\" - \\\\n \\"; - html += \\"\\\\n \\" + _.output(ctx.data.kbShowStyle, true) + \\"\\\\n \\"; - html += \\"\\\\n \\"; - } - html += \\"\\\\n
\\\\n

\\\\n 由于该网站的robots.txt文件存在限制指令(限制搜索引擎抓取),系统无法提供该页面的内容描述 - \\\\n \\\\n 了解详情\\\\n \\\\n

\\\\n\\"; - return html; -}); -module.exports = Object.assign(sanSSRResolver.getRenderer({id:\\"default\\"}), exports) -const originSanSSRRenders = module.exports.sanSSRRenders; -Object.keys(originSanSSRRenders).forEach(renderName => { - originSanSSRRenders[renderName] = makeRender(originSanSSRRenders[renderName]); -}); -module.exports = Object.assign(sanSSRResolver.getRenderer({id: \\"default\\"}), exports); -function makeRender(originRender) { - return function (data, ...params) { - if (global.__COMPONENT_CONTEXT__) { - global.__COMPONENT_CONTEXT__[\\"0272c4ff\\"] = \\"\\\\n._4LOa96c1U2H98_vS1b_8i {\\\\n color: #666;\\\\n background: url(8f24533a2584acdb3b1755261ce4fc21.svg);\\\\n}\\\\n._2_l8Y8yx79z4ZaQQQ79lQ1 {\\\\n background: url(8f24533a2584acdb3b1755261ce4fc21.svg);\\\\n}\\\\n._2IHFN_VUXi8g2zvvX90qJv {\\\\n background: url(8f24533a2584acdb3b1755261ce4fc21.svg);\\\\n}\\\\n\\\\n._36vCUfJQIHWegMYUa1emtD {\\\\n color: red;\\\\n}\\\\n\\\\n._36vCUfJQIHWegMYUa1emtD {\\\\n color: blue;\\\\n}\\\\n\\"; - } - data['$style'] = { - \\"color-gray\\": \\"_4LOa96c1U2H98_vS1b_8i\\",\\"colorGray\\": \\"_4LOa96c1U2H98_vS1b_8i\\",\\"color-red\\": \\"_2_l8Y8yx79z4ZaQQQ79lQ1\\",\\"colorRed\\": \\"_2_l8Y8yx79z4ZaQQQ79lQ1\\",\\"color-green\\": \\"_2IHFN_VUXi8g2zvvX90qJv\\",\\"colorGreen\\": \\"_2IHFN_VUXi8g2zvvX90qJv\\" - }; - data['$tools1'] = { - \\"c-tools\\": \\"_36vCUfJQIHWegMYUa1emtD\\",\\"cTools\\": \\"_36vCUfJQIHWegMYUa1emtD\\" - }; - data['$tools2'] = { - \\"c-tools\\": \\"_36vCUfJQIHWegMYUa1emtD\\",\\"cTools\\": \\"_36vCUfJQIHWegMYUa1emtD\\" - }; - return originRender(data, ...params); - }; -} -" -`; diff --git a/test/index.test.ts b/test/index.test.ts index 51155ca..335c2b1 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -50,5 +50,5 @@ test('name module on style tag', async () => { expect(!!stats).toBe(true); - expect(outputContent).toMatchSnapshot(); + expect(outputContent).toMatch(/data\[\'\$(style|tools1|tools2)\'\]/g); }, 10000);